[英]Get data from joined table in mysql
Please check the image. 请检查图像。
Here i have 2 table. 在这里,我有2张桌子。 One is post table and another is fevorite table.
一个是邮政桌,另一个是收藏桌。 Both has primary key and
post_id
is FOREIGN_KEY in fevorite table. 两者都具有主键,并且收藏夹表中的
post_id
为FOREIGN_KEY。
Now my needs are : 现在我的需求是 :
I need all of those things in single query. 我需要在单个查询中所有这些东西。 Thanks in advance.
提前致谢。
Use sub query to get your result: 使用子查询获取结果:
SELECT * FROM Post WHERE post_id IN (
SELECT post_id FROM fevorite WHERE fevorite_by = 2)
Or you can do it by JOIN 或者您可以通过JOIN完成
SELECT P.*
FROM Post P
JOIN fevorite F ON F.post_id = P.post_id
WHERE F.fevorite_by = 2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.