MYSQL:如何在两次引用同一张表的同一查询上联接两个表 [英] MYSQL: How to JOIN two tables on the same query referencing the same table twice
本文介绍了MYSQL:如何在两次引用同一张表的同一查询上联接两个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个桌子.我试图将下面的两个示例表与表1结合起来,两次引用表2.例如,如果我查看表1:第2组和成员7,则应在表2中查找ID,并提供以下输出:
I have two tables. I'm trying to JOIN the sample two tables below with table 1 referencing Table 2 twice. For example if I look at Table 1: Group 2 and Members 7, it should look up the ID in Table 2 and give me an output of:
Group Members Name Name
2 7 Blue Dog
表1
Group Members
2 7
3 8
5 10
表2
ID Name
1 Green
2 Blue
3 Yellow
4 Orange
5 Red
6 Elephant
7 Dog
8 Cat
9 Chicken
10 Mouse
有什么建议吗?谢谢
推荐答案
SELECT
Table_1.*,
g.Name,
m.Name
FROM
Table_1
INNER JOIN Table_2 AS g ON Table_1.Group=g.ID
INNER JOIN Table_2 AS m ON Table_1.Group=m.ID
WHERE
Table_1.Group=2
AND Table_1.Member=7
这篇关于MYSQL:如何在两次引用同一张表的同一查询上联接两个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文