MYSQL 嵌套 select 查询 *
MYSQL nested select query with *
我有一个名为事件的 table,它有以下字段:
`index`, `timestamp`, `refNum`, `priority`, `status`, `type`, `email`, `telephone`, `title`, `description`, `system`, `category`, `time`, `requiredBy`, `dateReason`, `oneOff`, `url`, `browserDevice`, `jsessionid`, `customersProducts`, `investigationsUndertaken`, `whatquestions`, `supportingInformation`, `open`
我对尝试嵌套查询还很陌生,我正在尝试 select 我事件中的所有记录 table 其中标题或状态与关键字匹配,然后我只想要结果发生在 selected 时间戳范围之间。此处的各个查询均独立运行,结果为 return,但当我尝试嵌套它们时,出现错误 #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%')
理想情况下,我想 return 所有字段,因此使用 *,它在我的时间戳范围和状态或标题之间包含我指定的关键字。在上面的示例查询中,我使用了关键字 'test'.
当您编写子查询时,通常希望您为主查询提供索引列 return。您不能 return SELECT *
因为没有隐式列可以关闭。我选择了 index
(希望这实际上是一个索引)
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%')
我有一个名为事件的 table,它有以下字段:
`index`, `timestamp`, `refNum`, `priority`, `status`, `type`, `email`, `telephone`, `title`, `description`, `system`, `category`, `time`, `requiredBy`, `dateReason`, `oneOff`, `url`, `browserDevice`, `jsessionid`, `customersProducts`, `investigationsUndertaken`, `whatquestions`, `supportingInformation`, `open`
我对尝试嵌套查询还很陌生,我正在尝试 select 我事件中的所有记录 table 其中标题或状态与关键字匹配,然后我只想要结果发生在 selected 时间戳范围之间。此处的各个查询均独立运行,结果为 return,但当我尝试嵌套它们时,出现错误 #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%')
理想情况下,我想 return 所有字段,因此使用 *,它在我的时间戳范围和状态或标题之间包含我指定的关键字。在上面的示例查询中,我使用了关键字 'test'.
当您编写子查询时,通常希望您为主查询提供索引列 return。您不能 return SELECT *
因为没有隐式列可以关闭。我选择了 index
(希望这实际上是一个索引)
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%')