MySQL - 在另一个查询中使用来自一个查询的结果 [英] MySQL - Using results from one query in another query
本文介绍了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.
这篇关于MySQL - 在另一个查询中使用来自一个查询的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文