SQL Learning (Five) multi-table associated -join

  In the actual work will be used in multi-table joint investigation, this time need to use the keyword JOIN

A, Inner the Join (en)

  Return line has at least one match, returns only two rows of the table is equal to the connection field

  Such as:

  select * from ticket

  inner join job

  on ticket.id=job.t_id

  Just check out, ticket.id = job.t_id data

Two, left the Join (left connection)

  Even if the right table does not match, it returns all rows from the left table

  Such as:

  select * from ticket

  left join job

  on ticket.id=job.t_id

  Whether ticket.id is not equal job.t_id , first returned ticket all the data; if ticket.id = job.t_id , the return of the corresponding job data; if ! Ticket.id = job.t_id , the corresponding job data displayed as null

Three, right the Join (right connection)

  Even if the left table does not match, it returns all rows from the right table

  Such as:

  select * from ticket

  right join job

  on ticket.id=job.t_id

  Whether ticket.id is not equal job.t_id , first returned job all the data; if ticket.id = job.t_id returned when the appropriate ticket transactions; if ! Ticket.id = job.t_id , the corresponding ticket data is null

Four, Full the Join (external connection)

  As long as there is a match where a table, then returns rows (two rows in the table return)

  Such as:

  select * from ticket

  full join job

  on ticket.id=job.t_id

  Whether ticket.id is not equal job.t_id , first returned ticket and job all the data; if ticket.id = job.t_id when will the corresponding ticket display data after job data; if ticket.id = job.t_id! when, Ticket data and job data on two lines, the corresponding data are shown side null

Guess you like

Origin www.cnblogs.com/smallstone2018/p/11165441.html