mysql - 使用 MySQL 查询的结果作为下一个的 WHERE 子句

标签 mysql sql subquery

我想使用以下 MySql 查询作为主查询中 WHERE 子句的输入,但我找不到正确的方法来执行此操作。我可以使用任何网站或示例来学习如何执行此操作吗?

代码如下:

主要查询:

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

子查询:

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'

最佳答案

尝试使用 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'))

参见下面的示例:

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

关于mysql - 使用 MySQL 查询的结果作为下一个的 WHERE 子句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51323005/

相关文章:

mysql - 如何找到其他字段中数据独有的字段?

mysql - 尝试在 View 创建中添加更新

mysql - 无法读取输入文件: Pig store to MYSQL using DBStorage

mysql - 如何在 MySQL 中重新索引计数器以连续递增?

PHP - CSV 到表未按预期转换

SQLite子查询语法/错误/与MySQL的区别

mysql - 从满足某些要求的表中获取数据

mysql - 将 mysql 子查询转换为 codeigniter

mysql - 选择与外国 ID 匹配的两行?

php - 如何使用 getAllChecked() 获取 dhtmlx 中检查的项目的文本