我正在做一个SQL练习:列表对的黑客都赢得了defcon竞赛,它们诞生于1990年之后。只列出每对一次。
也就是说,您的查询不应同时返回(zix,wix)和(wix,zix)。
我有3张桌子
黑客在两个表中引用hackers.name
- > winners
和white_paper
如何在没有排列的情况下返回每对黑客的名字?
我失败的尝试:
select
name, hacker
from
hackers
join
winners on hacker = hackers.name
where
name != hacker
group by
country ;
答案 0 :(得分:0)
尝试这应该工作
select A1.name as name1, A2.name as name2
from hackers A1, hackers A2, winners
and winners.hacker = A1.name
and winners.hacker = A2.name
where A1.birthday > 1990
and A2.birthday > 1990
and A1.name > A2.name /* this code is the one who help to avoid duplicate
pair */