Connection query-right connection

1. Right join query

Based on the right table, query the data in the left table according to the conditions, if the data in the left table does not exist according to the conditions, use the null value to fill

Right connection query effect chart:

Right connection query effect chart:

 

Right join query syntax format:

select 字段 from 表1 right join 表2 on 表1.字段1 = 表2.字段2

Description:

  • right join is the right join query keyword
  • on is the connection query condition
  • Table 1 is the left table
  • Table 2 is the right table

Example 1: Use right join to query student table and class table:

select * from students as s right join classes as c on s.cls_id = c.id;

 

Right join query

select * from students s right join classes c on s.c_id=c.id;

select * from students s right join classes c on s.c_id=c.id;  ​

Right join query, query the left table according to the right, if the data in the left table does not exist, use null to fill.

Right is the left table on the left, and right is the right table on the right.

 

2. Summary

  • Right join use right join .. on .., on indicates the join query condition of the two tables
  • The right join mainly uses the right table to query the data in the left table according to the conditions, and the data in the left table does not exist and is filled with null values.

Guess you like

Origin blog.csdn.net/weixin_48135624/article/details/115237868