简体   繁体   English

如果表2中存在数据,则MySQL从表1中选择

[英]MySQL select from table 1 if data exists in table 2

So I have 2 tables. 所以我有2张桌子。 The first one favorites contains users favorite tv shows (structure below). 第一个favorites包含用户喜欢的电视节目(下面的结构)。 The second one episodes has a column permalink as well as other data about each episode. episodes具有列permalink以及有关每个集的其他数据。 I want to select everything from episodes with permalink = show_permalink and userid = 32 . 我想从具有permalink = show_permalinkuserid = 32 episodes选择所有内容。 Could anyone help me with the query? 有人可以帮我查询吗?

Table: favorites

id |  userid  |   show_permalink 
----------------------------------
1  |  32      |   the-strain 
2  |  5       |   still-the-king 
3  |  32      |   game-of-thrones 

Episodes table: 情节表:

情节表

If both column has same data type then it will work 如果两列具有相同的数据类型,则它将起作用

SELECT episodes.* FROM episodes 
INNER JOIN favorites ON(favorites.show_permalink = episodes.permalink) 
where favorites.userid = 32

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM