确认我写的查询是否适合mysql



我有这个查询

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

然而,如果DateTimeCreatedDateTimeStamp被索引,您的查询可能会运行得更快。在OR条件下,MySQL不擅长使用索引。