Natural join connects two tables using common column names, and it uses the using
clause. Other joins use the on
clause.
Try this:
SELECT table1.data2
FROM table1 LEFT JOIN
table2
on table1.nlm = table2.`#nlm`
WHERE table2.pid = 3;
Вопрос
so i have 2 tables with the following data
*where a star is a primary key.
*and a # is a unique key.
Table 1
╔══════╦═══════╦════════╗
║ #nlm ║ data2 ║ *data3 ║
╚══════╩═══════╩════════╝
Table 2
╔══════╦═════╗
║ *pid ║ nlm ║
╚══════╩═════╝
The goal is to get data2 when I know pid. I've tried this, and failed badly.
SELECT data2 FROM table1 LEFT JOIN table2 USING nlm WHERE pid = 3;
Решение
Natural join connects two tables using common column names, and it uses the using
clause. Other joins use the on
clause.
Try this:
SELECT table1.data2
FROM table1 LEFT JOIN
table2
on table1.nlm = table2.`#nlm`
WHERE table2.pid = 3;
Другие советы
The USING
clause requires that the column names be in parentheses:
SELECT data2 FROM table1
INNER JOIN table2 USING (nlm)
WHERE pid = 3
This should also be an INNER JOIN, since the WHERE
clause requires that it find a row in table2
.