Home > OS >  SQL Query Duplicates Values
SQL Query Duplicates Values

Time:01-14

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

CodePudding user response:

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
  •  Tags:  
  • Related