Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Join 3 tables

Author  Topic 

lio1972
Starting Member

19 Posts

Posted - 2012-08-01 : 10:59:10
Hi everione.This query suppost to return one row ,but returns zero
What I am doing wrong
SELECT recipe.id,recipe.name, recipe.posted_by, recipe_images.image_link, recipe_video.video
FROM recipe
JOIN recipe_images ON recipe.id = recipe_images.id
JOIN recipe_video ON recipe.id = recipe_video.id
WHERE recipe.id=4;

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-08-01 : 11:13:00
May be not all recipies have a video and an image. You can find out for this specific case by running these queries. In each case, it has to return at least one row if you are to get any output in your query.
SELECT * FROM recipe WHERE id = 4;
SELECT * FROM recipe_images WHERE id = 4;
SELECT * FROM recipe_video WHERE id = 4;
If that is not the case, change the JOINs to LEFT JOINs.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-01 : 11:16:03
may be relationship specified is wrong

unless we see some sample data and have an idea of what you're trying to do we can only guess!

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

lio1972
Starting Member

19 Posts

Posted - 2012-08-01 : 11:38:13
Thank you for the help ,the problem was that there was no video with id 4
Thank you again
Go to Top of Page
   

- Advertisement -