How would I go about writing a query in MySQL on 3 different tables? Here's what I have so far:
我如何在3个不同的表上编写MySQL查询?这是我到目前为止所拥有的:
SELECT distinct cool_id, example, table1.name
FROM tardis
INNER JOIN table1
ON table1.unique_id = table2.unique_id
AND table1.unique_id='12345'
AND table2.status='active'
Now let's say that there is a column called 'planets' that exists in a 3rd table. How would I add that to this query to select 'planets' in addition to matching the other conditions in my current query? Also, please advise if an INNER JOIN is not the best choice for this.
现在让我们说第3个表中存在一个名为“planets”的列。除了匹配当前查询中的其他条件外,我如何将其添加到此查询中以选择“行星”?另外,如果INNER JOIN不是最佳选择,请告知。
1 个解决方案
#1
0
Just add another INNER JOIN
clause:
只需添加另一个INNER JOIN子句:
SELECT columns
FROM table1
INNER JOIN table2 ON table1.col1 = table2.col2
INNER JOIN table3 ON table1.somecol = table3.othercol
The ON
condition in the second join can refer to columns from table1
, table2
, or both.
第二个连接中的ON条件可以引用table1,table2或两者中的列。
#1
0
Just add another INNER JOIN
clause:
只需添加另一个INNER JOIN子句:
SELECT columns
FROM table1
INNER JOIN table2 ON table1.col1 = table2.col2
INNER JOIN table3 ON table1.somecol = table3.othercol
The ON
condition in the second join can refer to columns from table1
, table2
, or both.
第二个连接中的ON条件可以引用table1,table2或两者中的列。