Home > database >  Relationship using PostgreSQL
Relationship using PostgreSQL

Time:04-30

Here i have attached the error displayed in postgreSQL. Here the Book_Detail is one table and Binding_Detail is another table. Primary Key is Book_Id and Foreign Key is Binding_Id.

SELECT b.Book_Title, e.Binding_Id, FROM Book_Details b, Binding_Details e WHERE b.Binding_Id = e.Binding_Id;

ERROR: syntax error at or near "FROM" LINE 2: FROM Book_Details b, Binding_Details e ^ SQL state: 42601 Character: 37

CodePudding user response:

The problem in your case is the comma before the FROM. You must remove this. By the way I highly recommend to do not use this syntax "FROM table a, table B", but to use JOIN instead.

CodePudding user response:

You need to remove the comma after e.Binding_Id

SELECT b.Book_Title, e.Binding_Id 
FROM Book_Details b, Binding_Details e 
WHERE b.Binding_Id = e.Binding_Id;

It would be better to use a JOIN

SELECT b.Book_Title, e.Binding_Id 
FROM Book_Details b
INNER JOIN Binding_Details e 
ON b.Binding_Id = e.Binding_Id;
  • Related