There are two tables named
Passenger (ID_psg, name)
Pass_in_trip (trip_no, date, ID_psg, place)
There can be several passengers bearing the same first name and surname (for example, Bruce Willis). My goal is to find the names of different passengers that ever travelled more than once occupying seats with the same number. It's exercise 63 given at sql-ex.ru
My Query at first try was
SELECT p.name
FROM pass_in_trip pt LEFT JOIN passenger p
ON pt.id_psg = p.id_psg
GROUP BY pt.id_psg, pt.place,p.name
HAVING COUNT(*) > 1
I am unable to find out the reason why it did not return the desired result. I know it can be done using subquery but I want to know where I am going wrong. The place column represent the seat number. You can take sql-server as database. Desired result should look something like this
name
--------
Bruce Willis
Nikole Kidman
Mullah Omar
group by?