dblabs/q.sql

12 lines
No EOL
492 B
SQL

--Is there more than one student with the same name? If so, who are these students? [7]
-- Selects duplicate students and counts them
-- SELECT firstName, lastName, count(*) as nbrOfStudents
-- FROM Students
-- GROUP BY firstName, lastName
-- HAVING count(*) > 1;
-- Selects all students with the same name, no grouping
SELECT DISTINCT S1.firstName, S1.lastName, S1.pNbr
FROM Students S1, Students S2
WHERE S1.firstName = S2.firstName AND S1.lastName = S2.lastName AND NOT S1.pNbr = S2.pNbr