Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have this query that gives me back rows with two columns each containing an id.

SELECT idEng, idDutch
FROM phraseConnections
WHERE cat = '3'

the id's are from other tables where they are connected to a phrase i want to get.

I tried something like this.

SELECT a.phrase, b.phrase
FROM phraseEnglish as a, phraseDutch as b
WHERE a.id = (SELECT idEng
FROM phraseConnections
WHERE cat = '3')
and b.id = (SELECT idDutch
FROM phraseConnections
WHERE cat = '3')

thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
160 views
Welcome To Ask or Share your Answers For Others

1 Answer

Better use Joins:

SELECT
   a.phrase,
   b.phrase
FROM
   phraseConnections pc
INNER JOIN
   phraseEnglish AS a
ON
   pc.idEng = a.id
INNER JOIN
   phraseDutch AS b
ON
   pc.idDutch = b.id
WHERE
   pc.cat = 3;

If you want records that have no corresponding row in one (or both) language too then you could use outer joins.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...