[英]Sql query to select different row with same ID
我要和“ funky”一起去;
SELECT y.*
FROM my_table x
JOIN my_table y
ON y.id = x.id
AND y.feature <> x.feature
WHERE x.feature = 'one';
正如Strawberry所說,您可以使用內部聯接:
SELECT f2.feature
FROM feature f1
INNER JOIN feature f2 ON f1.id = f2.id AND f1.feature <> f2.feature
WHERE f1.feature='one'
一種實現方法是使用exists
運算符:
SELECT *
FROM features f_outer
WHERE EXISTS (SELECT *
FROM features f_inner
WHERE f_outer.id = f_inner.id AND
f_outer.feature != f_inner.feature AND
f_inner.feature = 'one')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.