JANNURM
JANNURM

Reputation: 331

Sql joining query

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

Answers (4)

Tikkes
Tikkes

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

Uma
Uma

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

Kshitij
Kshitij

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

Nadir Sampaoli
Nadir Sampaoli

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

Related Questions