SQL语法混淆(自然加入)

时间:2014-12-11 07:28:41

标签: sql postgresql join

以下代码

postgres=# SELECT title,name,borrower.address WHERE library_branch NATURAL JOIN
book NATURAL JOIN book_loans NATURAL JOIN borrow WHERE library_branch.branchname
='Sharpstown' AND dateOut='12/10/2014';
ERROR:  syntax error at or near "NATURAL"
LINE 1: ... title,name,borrower.address WHERE library_branch NATURAL JO...
                                                         ^
postgres=#

不确定为什么会出错。我以为我正确地做了自然连接。有什么建议吗?

1 个答案:

答案 0 :(得分:0)

where应该有一个from关键字:

SELECT       title, name, borrower.address 
FROM         library_branch -- There's a WHERE here in the OP
NATURAL JOIN book 
NATURAL JOIN book_loans 
NATURAL JOIN borrow 
WHERE        library_branch.branchname = 'Sharpstown' AND 
             dateOut = '12/10/2014';