MySQL 左连接 left join 右连接 right join 内连接 inner join

MySQL 左连接 left join 右连接 right join 内连接 inner join

#获取两个表中字段匹配关系的记录
select a.user_code, a.user_name, b.user_code, b.user_name from app_users a inner join app_users_bak b on a.user_code = b.user_code
#获取左表所有记录,即使右表没有对应匹配的记录
select a.user_code, a.user_name, b.user_code, b.user_name from app_users a left join app_users_bak b on a.user_code = b.user_code;
#获取右表所有记录,即使左表没有对应匹配的记录
select a.user_code, a.user_name, b.user_code, b.user_name from app_users a right join app_users_bak b on a.user_code = b.user_code

 

发表回复

您的电子邮箱地址不会被公开。