在MySQL JOIN查询中获取重复项

时间:2022-10-13 12:54:57

I needed to join 2 tables together in a query and have the query executing properly except it is listing duplicates of the data? I only need one copy of each record returned.

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

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

Returns:

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 个解决方案

#1


1  

SELECT DISTINCT <rest of your query goes here>

#1


1  

SELECT DISTINCT <rest of your query goes here>