question

Anas avatar image
Anas asked

where statement problem

Select p_firstname, p_email From teacher , borrowed where teacher.p_id and borrowed.p_id =055511 ; the code works perfectly without "where" statement, once i add it, it gives me error. why ?
errorwhere
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

JohnM avatar image
JohnM answered
The WHERE clause is incorrect. You need to define some type of equality for teacher.p_id. Like this: WHERE teacher.pid = 055511 AND borrowed.p_id = 0555111; Also, your join syntax is outdated. The better way would be to declare an INNER JOIN like this: FROM dbo.teacher t INNER JOIN dbo.borrowed b on t.p_id = b.p_id --(or some matching criteria) Reference: http://straightpathsql.com/archives/2012/11/sql-server-join-syntax-its/ Hope that helps!
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Anas avatar image
Anas answered
![thank you for replying, but unfortunately, it did not work, i uploaded a picture][1] thank you for replying, but unfortunately, it did not work, i uploaded a picture [1]: /storage/temp/3867-lms-database.jpg

lms-database.jpg (148.8 KiB)
4 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Try this: SELECT p_firstname, p_email from teacher t inner join borrowed b on t.p_id = b.p_id where t.p_id = '0888654'
0 Likes 0 ·
still the same result, besides: the borrowed table consist of ids of teachers and students who borrowed books, so i need the "where" to compare the borrowed id table with teacher id table to get only the teachers names and emails who borrowed books (without students )
0 Likes 0 ·
What is the table structure for both tables? Can you post that? Can you try this: Select p_firstname, p_email From teacher , borrowed where teacher.p_id = '055511' and borrowed.p_id ='055511' ;
0 Likes 0 ·
eventually it worked, there was a problem in the structure of some tables... thank you so much for your help and sorry for delay replying
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.