答案 0 :(得分:2)
SELECT yt1.* , yt2.* /*SELECT both data, you can put * if you want too */
FROM yourtable yt1
INNER JOIN yourtable yt2 /*Do self-checking*/
ON yt1.alt_anim_ident = yt2.alt_anim_ident /*Check those with the same alt_anim_ident*/
WHERE yt11.animals_key <> yt2.animals_key; /*Eliminates data which pointing to itself*/
答案 1 :(得分:2)
SELECT *
FROM thetable t -- How to find animals
WHERE EXISTS ( -- where (different animals) exist
SELECT * FROM thetable x
WHERE x.alt_anim_ident = t.alt_anim_ident -- that have same ident
AND x.animals_key <> t.animals_key -- but different key
)
ORDER BY t.alt_anim_ident, t.animals_key
;