在MySQL JOIN查询中获取重复项

时间:2014-09-03 19:46:31

标签: mysql sql

我需要在查询中将两个表连接在一起并使查询正确执行,除非它列出数据的重复项?我只需要返回每条记录的一份副本。

SELECT DISTINCT FirstName, LastName, r.Email, ListingID 
FROM TableE e
JOIN TableR r ON e.ListingAgentID=r.AgentID 
WHERE ListingFirmID = 'JNA' 
ORDER BY ListPrice DESC

返回:

FirstName  |  LastName  |  Email      |  ListingID
-------------------------------------------------
Buck       |  Rogers    | buck@b.com  |  563214
Buck       |  Rogers    | buck@b.com  |  563214
Samm       |  Bogers    | samm@b.com  |  999999
Samm       |  Bogers    | samm@b.com  |  999999
Alan       |  Stoger    | Alan@b.com  |  232323
Alan       |  Stoger    | Alan@b.com  |  232323
Dann       |  Dammit    | dann@b.com  |  636363
Dann       |  Dammit    | dann@b.com  |  636363
Dann       |  Dammit    | dann@b.com  |  636363
Dann       |  Dammit    | dann@b.com  |  636363

1 个答案:

答案 0 :(得分:1)

SELECT DISTINCT <rest of your query goes here>