假如,我现在有两个表,(只是假设这个场景)
table_a 如下:
table_b 如下:
我现在需要对这两个表进行关联查询,把 stu_id 相同,stu_name 不同的记录找出来,可是这两个表中,实际 stu_id 相同,stu_name 不同的记录只有两条,那就是 stu_id = 555 和 stu_id = 666 的两条记录,其他都能对应得上,但是如果用关联查询的话,查询出来所有记录如下:
select a.stu_id stu_id, a.stu_name stu_name, b.stu_id stu_id_new, b.stu_name stu_name_new from table_a a join table_b b on a.stu_id = b.stu_id order by a.stu_id,a.stu_name;
全部都关联出来了,如果只要查找 stu_id 相同,stu_name 不同的,如下:
select a.stu_id stu_id, a.stu_name stu_name, b.stu_id stu_id_new, b.stu_name stu_name_new from table_a a join table_b b on a.stu_id = b.stu_id where a.stu_name <> b.stu_name order by a.stu_id,a.stu_name;
可是,这结果里面,我真正想要的只有下面画圈的那两条啊
遇到这种情况,我该如何查出我要的结果来???