select a.* from student a,student b where a.sname=b.sname and a.sid!=b.sid是查单表重复记录吗

来源:百度知道 编辑:UC知道 时间:2024/05/04 11:11:29
select a.* from student a,student b where a.sname=b.sname and a.sid!=b.sid是查单表重复记录吗
为什么列名要用a.和b.来区分?

这个SQL查询出来的结果是表student中sid不同但sname相同的记录

用a和b来区分,就相当于两个相同的表之间的一个关联的查询

是联表查询,此处为内联接,即查询当a.sname=b.sname and a.sid!=b.sid时的结果。a、b是表的别名,用于区分不同表相同的字段名。

因为 两个表中存在相同的列名,不用就无法知道你表示的是哪个表的列!