Reputation: 331
I have a Query
SELECT foodjoint_id FROM provider_food_joints WHERE foodjoint_name='".$foodjoint_name."'";
Now I have to select all Info from another table which have a foodjoint_id filed
SELECT * from menu_item where foodjoint_id = THOSE ID
I have to join those two Query
Upvotes: 0
Views: 120
Reputation: 4689
SELECT i.menu_item
FROM menu_item i
JOIN provided_food_joints pfj
ON (pfj.id = i.foodjoin_id)
WHERE i.foodjoin_id = 5
This is basically how a join statement works. Check out this tutorial for more information on different kind of joins
In your case - as suggested by nadirs - JOIN
statements would be more useful.
Upvotes: 2
Reputation: 59
SELECT * FROM menu_item WHERE foodjoint_id = (SELECT foodjoint_id FROM provider_food_joints WHERE foodjoint_name='".$foodjoint_name."'");
Hope this is what your are asking? or be specific about the question
Upvotes: 0
Reputation: 8644
try this
SELECT * from menu_item where foodjoint_id in( SELECT foodjoint_id FROM provider_food_joints WHERE foodjoint_name='".$foodjoint_name."'")
Upvotes: 1
Reputation: 5555
You can use the IN clause in your condition:
SELECT * from menu_item where foodjoint_id IN (
SELECT foodjoint_id FROM provider_food_joints WHERE foodjoint_name='".$foodjoint_name."'");
Upvotes: 1