我在使用以下 SQL INNER JOIN 语句时遇到问题。我可能在语法上遗漏了一些东西:
SELECT * from
(SELECT DISTINCT Name from Table.Names WHERE Haircolor='Red') uniquename
INNER JOIN
(SELECT * FROM Table.Names) allnames
ON uniquenames.Name = allnames.Name;
我想要所有头发颜色为“红色”的名字,但我不想要任何重复的名字。
NAME HAIRCOLOR ADDRESS PHONE EMAIL
----- --------- ------- ----- -----
Joe Red 123 Street 20768422 blah@example.com
Joe Red 828 Street 703435422 blah4@example.com
Joe Red 165 Street 10768422 blah3@example.com
Jamie Blond 4655 Street 10568888 blah3@example.com
John Brown 941 Street 40768422 blah5@example.com
Josephine Red 634 Street 43444343 blah2@example.com
Josephine Red 394 Street 43414343 blah7@example.com
查询应返回:
NAME HAIRCOLOR ADDRESS PHONE EMAIL
----- --------- ------- ----- -----
Joe Red 123 Street 20768422 blah@example.com
Josephine Red 634 Street 43444343 blah2@example.com
也许它涉及 GROUP BY?