所以我有 2 个包含以下数据的表
*where a star is a primary key.
*and a # is a unique key.
表1
╔══════╦═══════╦════════╗
║ #nlm ║ data2 ║ *data3 ║
╚══════╩═══════╩════════╝
表2
╔══════╦═════╗
║ *pid ║ nlm ║
╚══════╩═════╝
目标是当我知道 pid 时获取 data2。我已经尝试过这个,但非常失败。
SELECT data2 FROM table1 LEFT JOIN table2 USING nlm WHERE pid = 3;
最佳答案
自然连接使用公共(public)列名连接两个表,并使用 using
子句。其他连接使用 on
子句。
试试这个:
SELECT table1.data2
FROM table1 LEFT JOIN
table2
on table1.nlm = table2.`#nlm`
WHERE table2.pid = 3;
关于mysql - SQL 自然连接和 use 子句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16721748/