我有这个查询
SELECT * FROM table1 WHERE
DateTimeCreated > now() - interval 30 minute and (cust is not null and (CustomerID != 0))
UNION
SELECT * FROM table1 WHERE
DateTimeStamp > now() - interval 30 minute and (cust is not null and (CustomerID != 0))
limit 1000
它会得到正确的记录吗?还是有另一种方法来做同样的事情
请指导
感谢您可以对OR
使用单个查询。
SELECT *
FROM table1
WHERE (DateTimeCreated > now() - interval 30 minute OR DateTimeStamp > now() - interval 30 minute)
AND cust is not null and CustomerID != 0
然而,如果DateTimeCreated
和DateTimeStamp
被索引,您的查询可能会运行得更快。在OR
条件下,MySQL不擅长使用索引。