MySQL - 在另一个查询中使用来自一个查询的结果

MySQL  - 在另一个查询中使用来自一个查询的结果

问题描述:

我有这个查询,返回的行有两列,每个列包含一个id。

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

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

id来自其他表他们连接到一个我想得到的短语。

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

我试过这样的。

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')

感谢。


$ b

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.