MySQL:从一个查询中返回Mulitple ID,并在“ in”中传递该值另一个查询
假设我有一个查询:
SELECT `id` FROM `tablename`
这将返回一些行中的一些ID。现在,我想使用这些ID来从另一个表中获取具有“ IN”功能的数据。
SELECT `somecol` FROM `anothertable` WHERE `parent` IN ( {IDs here} )
我可以使用2个不同的查询使用PHP执行此操作。但是我想知道仅使用一个查询单独使用MySQL来完成或可以做到这一点?
So let's say that I have a query:
SELECT `id` FROM `tablename`
This will returns some IDs in rows. Now I want to use these IDs to get data from another table with the 'IN' function.
SELECT `somecol` FROM `anothertable` WHERE `parent` IN ( {IDs here} )
I could do this with PHP using 2 different queries. But I wanted to know how or can it be done with MySQL alone, using only one query?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用存在:
Use exists:
只需传递您的第一个查询您的第二个查询:
Just pass in your first query inside you second query: