我有一个名称和地址表(FirstName,LastName,Address)。我想选择每个地址的人都有多个姓的行。例如,如果John Smith和Jane Brown居住在同一地址。访问不能做SELECT(DISTINCT(LastName))所以我不知道如何解决这个问题。
下面给了我不止一个人的地址,但我不知道从哪里开始。
SELECT FirstName, LastName, Address
FROM List
WHERE (Address) IN
(SELECT Address FROM List GROUP BY (Address) HAVING COUNT(Address) > 1);
感谢您的帮助!
答案 0 :(得分:1)
相反,请比较min()
和max()
:
SELECT FirstName, LastName, Address
FROM List
WHERE Address IN (SELECT Address FROM List
GROUP BY Address HAVING MIN(LastName) <> MAX(LastName));