I would like to seek the advice of some sql experts.
I wrote sql statement for getting authors names from staff and alumni table. Some author's name will be in both tables. So the logic is if the author name is in staff, use that otherwise look for alumni table.
Here is my sql statement, seems fine but it is showing same author name from both staff and alumni table.
SELECT DISTINCT AP.Author_name, P.people_id, P.Name, P.Journal_name, AP.Author_sortorder FROM `Paper_Author` AS AP LEFT JOIN `People` AS P ON ( AP.Author_id = P.people_id ) WHERE AP.Paper_id =3838 UNION SELECT DISTINCT AN.Author_name, N.People_id, N.Name, N.Journal_name, AN.Author_sortorder FROM `Paper_Author` AS AN LEFT JOIN `Alumni` AS N ON ( AN.Author_id = N.People_id ) WHERE AN.Paper_id =3838 ORDER BY Author_sortorder LIMIT 0 , 30 Result:
people_id-- Author_name-- Journal_name-- 1 Name1 A1 2 Name2 B1 3 Name3 C1 3 Name3 C1 4 Name4 D 4 Name4 Expected Result :
people_id-- Author_name-- Journal_name-- 1 Name1 A1 2 Name2 B1 3 Name3 C1 4 Name4 D
group by?