简体   繁体   English

接下来将MySQL查询的结果用作WHERE子句

[英]Using outcome of MySQL query as WHERE clause for next

I would like to use the following MySql query as an input for the WHERE clause in the main query, but I cannot find the correct way to do this. 我想使用以下MySql查询作为主查询中WHERE子句的输入,但是我找不到正确的方法来执行此操作。 Is there any site or example I can use in order to learn how to do this? 我可以使用任何网站或示例来学习如何执行此操作吗?

Code is as follows: 代码如下:

MAIN Query: 主要查询:

SELECT *, IF(SubQuery is true, 'Yes', 'No') AS Watched Distribution
FROM account
WHERE Watched Distribution LIKE 'Yes'

SubQuery: 子查询:

SELECT account_id, IF(w.main_title RLIKE 'place holder for film 
titels|nextfilm|nextfilm', 'Distribution', 'Non-distribution') AS Distribution
FROM watched w
WHERE Distribution LIKE 'Distribution'

Try to use JOIN operator and where clause like this: 尝试使用JOIN运算符和where子句,如下所示:

SELECT a.*, 'Yes'
FROM account a
JOIN watched w on w.account_id = a.account_id
where 'Distribution' in (IF(w.main_title RLIKE 'place holder for film 
titels|nextfilm|nextfilm', 'Distribution', 'Non-distribution'))

See example below: 请参见下面的示例:

https://www.sitepoint.com/community/t/mysql-question-how-to-us-an-as-field-in-the-where-clause/1188/5 https://www.sitepoint.com/community/t/mysql-question-how-to-us-an-as-field-in-the-where-clause/1188/5

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

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