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.
解决方案
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.