Join Statement


Inner Join

 

Sample

Note

select * from

invoices, clients

where

invoices.id = clients.id

The benefit of this join in the example, is that it will retrieve all of the information from both the invoices and clients tables wherever an invoices.id = clients.id.   In short result set will return a value if there's an exact match or the conditions are correct


Left Join

 

Sample

Remarks

Select *

from clients

left join invoices on

invoices.id = clients.id

  • All data from clients will be retrieved
  • All data from invoices will be retrieved as long as a match is made

Select *

from clients

left join invoices

Using(id)

  • If both tables have the same column name for linking, you can simplify your query with the key word Using(common column name)
  • will retrieve every client column
  • compare it to appropriate invoices with similar id column value
  • even If a client has NO invoices
  • In Short clients table is the Parent and invoices table is the child