MYSQL:根据其他查询的结果显示数据.想要合并查询



我有两个查询,A和B,查询B只能运行,如果我得到查询A的结果,但现在我分别做两个查询。以下是我的查询:

查询

SELECT id, u_name, u_email, u_factory_id FROM wla_user WHERE email = 'john@gmail.com'
<表类>idu_nameu_emailu_factory_idtbody><<tr>1约翰鸟john@gmail.com8

使用联合查询:

SELECT id, u_name, u_email, u_factory_id
FROM wla_user
WHERE email = 'john@gmail.com'
UNION ALL
SELECT id, door_details, con_details, factory_id
FROM wla_container
WHERE factory_id = $u_factory_id;

根据MySQL文档,当您需要查询a的结果来运行查询B时,您可以使用嵌套查询,如下所示:

查询

SELECT id, door_details, con_details, factory_id 
FROM wla_container 
WHERE factory_id IN (
SELECT u_factory_id 
FROM wla_user 
WHERE u_email = 'john@gmail.com'
);
<表类>iddoor_detailscon_detailsfactory_idtbody><<tr>12 Tan汽车零配件823 Tan摩托车零配件833 Tan厨房8

相关内容

  • 没有找到相关文章

最新更新