[英]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 现在,我必须从另一个表中选择一个包含foodjoint_id的所有信息
SELECT * from menu_item where foodjoint_id = THOSE ID
I have to join those two Query 我必须加入这两个查询
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. 基本上,这就是join语句的工作方式。 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. 在你的情况-由最低点的建议-
JOIN
语句会更有用。
You can use the IN clause in your condition: 您可以在条件中使用IN子句:
SELECT * from menu_item where foodjoint_id IN (
SELECT foodjoint_id FROM provider_food_joints WHERE foodjoint_name='".$foodjoint_name."'");
尝试这个
SELECT * from menu_item where foodjoint_id in( SELECT foodjoint_id FROM provider_food_joints WHERE foodjoint_name='".$foodjoint_name."'")
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
或具体说明问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.