Php MYSQL嵌套选择查询*

Php MYSQL嵌套选择查询*,php,mysql,select,join,nested,Php,Mysql,Select,Join,Nested,我有一个名为“事件”的表,它有以下字段: `index`, `timestamp`, `refNum`, `priority`, `status`, `type`, `email`, `telephone`, `title`, `description`, `system`, `category`, `time`, `requiredBy`, `dateReason`, `oneOff`, `url`, `browserDevice`, `jsessionid`, `customersProdu

我有一个名为“事件”的表,它有以下字段:

`index`, `timestamp`, `refNum`, `priority`, `status`, `type`, `email`, `telephone`, `title`, `description`, `system`, `category`, `time`, `requiredBy`, `dateReason`, `oneOff`, `url`, `browserDevice`, `jsessionid`, `customersProducts`, `investigationsUndertaken`, `whatquestions`, `supportingInformation`, `open`
我对尝试嵌套查询非常陌生,我正在尝试选择事件表中标题或状态与关键字匹配的所有记录,然后我只希望结果出现在所选时间戳范围之间。这里的两个查询都独立工作并返回结果,但当我尝试嵌套它们时,得到错误1241-操作数应该包含1列。我做错了什么

SELECT
    *
FROM
    `incidents`
WHERE
     `timestamp` BETWEEN '2014-12-01 00:00:00' AND '2015-11-23 23:59:59'  
IN
(SELECT * FROM `incidents` WHERE `title` LIKE '%test%' OR `status` LIKE '%test%')

理想情况下,我希望返回所有字段,因此使用*,它位于我的时间戳范围和包含我指定的关键字的状态或标题之间。在上面的示例查询中,我使用了关键字“test”。

当您编写子查询时,通常希望您为主查询提供一个要从中返回的索引列。您不能返回SELECT*,因为没有可设置关键帧的隐式列。我选择了索引,希望这实际上是一个索引

SELECT
    *
FROM
    `incidents`
WHERE
     `timestamp` BETWEEN '2014-12-01 00:00:00' AND '2015-11-23 23:59:59'  
AND index IN
(SELECT index FROM `incidents` WHERE `title` LIKE '%test%' OR `status` LIKE '%test%')

与使用SELECT*的子查询不同,您应该特别选择timestamp列或与之相关的列。使用子查询也没有意义。您可以将内部查询where子句移动到外部查询where子句。