简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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