简体   繁体   English

SQL 查询重复值

[英]SQL Query Duplicates Values

I'm running a query to see who hasn't signed up for classes, and whenever I do it, it duplicates the student information and displays them twice.我正在运行查询以查看谁还没有注册课程,每当我这样做时,它都会复制学生信息并显示两次。 Any reason query wise it would be doing this?有什么理由明智地查询它会这样做吗?

Here is the query.这是查询。

SELECT DISTINCT a.grade, a.lastname, a.firstname, a.sid 
FROM aspen a 
LEFT JOIN gh g ON a.sid = g.sid 
WHERE g.sid IS NULL 
order by a.grade, a.lastname, a.firstname

Since you aren't interested in any data from gh simply use not exists由于您对来自gh的任何数据不感兴趣,因此只需使用not exists

select grade, lastname, firstname, sid 
from aspen a 
where not exists (select * from gh where gh.sid = a.sid)
order by grade, lastname, firstname

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM