简体   繁体   English

如何内联两个匿名表 [SQL]

[英]How to Inner join two anonymous tables [SQL]

as the title states, Let's say i have three tables: person , autos , numbers .正如标题所述,假设我有三个表: personautosnumbers

Created已创建

First table with: INNER JOIN of person and autos First table有: INNER JOINpersonautos

Second Table with: INNER JOIN of autos and numbers Second Tableautosnumbers INNER JOIN

Question: Is it possible to INNER JOIN first and second table ?问题:是否可以INNER JOIN firstsecond table

You can join the two tables based on the autos part.您可以根据autos部分连接两个表。 Assuming it has an ID:假设它有一个ID:

SELECT *
FROM   first_table f
JOIN   second_table s ON f.auto_id = s.auto_id

You can do 2 joins (with 3 tables) together.您可以一起进行 2 个连接(使用 3 个表)。 Which are the keys for the joins?哪些是连接的键? personID for person and autos and on numbers personautos以及numbers personID

SELECT *
FROM person p
JOIN autos a ON p.keyA= a.keyA
JOIN numbers n ON a.keyB = n.keyB

Where keyA and keyB are the corresponding field on which you want to do the join.其中keyAkeyB是您要进行连接的相应字段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM