我有两张桌子作为父母和狗,我被要求
" JOIN表父母和狗,以及选择具有相同毛发类型的父母和孩子。只显示一次"
我真的不知道该怎么做
表1:父母(父母,孩子)
('abraham', 'barack')
('abraham', 'clinton')
('delano', 'herbert')
('eisenhower', 'fillmore')
('fillmore', 'abraham')
('fillmore', 'delano')
('fillmore', 'grover')
表2:狗(名字,毛皮)
('abraham', 'long')
('barack', 'short')
('clinton', 'long')
('delano', 'long')
('eisenhower', 'short')
('fillmore', 'curly')
('grover', 'short')
('herbert', 'curly')
答案 0 :(得分:-1)
你可以做的是:
SQL:
SELECT parent, child FROM parents as C JOIN
SELECT * FROM (SELECT A.parent, B.child
FROM (SELECT parent,
fur
FROM parents
JOIN dogs
ON parent=name) as A
JOIN
(SELECT child,
fur
FROM parents
ON child=name) as B
ON A.fur = B.fur) as D
ON C.parent = D.parent AND C.child = D.child