MySQL,PHP - 查询在使用datetime时获取所有记录[重复]

时间:2022-05-18 00:08:03

This question already has an answer here:

这个问题在这里已有答案:

I have query like this:

我有这样的查询:

SELECT * FROM messages
WHERE recipients LIKE '%0688427893%'
AND 'dateadded' > '2015-05-13 12:52:57'
ORDER BY dateadded ASC

This should select only messages that are added after 2015-05-13 12:52:57, but instead of doing that, it is selecting all messages. What am I doing wrong here?

这应该只选择在2015-05-13 12:52:57之后添加的消息,但不是这样做,而是选择所有消息。我在这做错了什么?

1 个解决方案

#1


SELECT * FROM messages
WHERE recipients LIKE '%0688427893%'
AND dateadded > '2015-05-13 12:52:57'
ORDER BY dateadded ASC

If you want to escape a column name in MySQL then use backticks

如果要在MySQL中转义列名,请使用反引号

`dateadded`

Using quotes turns it into a normal string

使用引号将其转换为普通字符串

'dateadded'

#1


SELECT * FROM messages
WHERE recipients LIKE '%0688427893%'
AND dateadded > '2015-05-13 12:52:57'
ORDER BY dateadded ASC

If you want to escape a column name in MySQL then use backticks

如果要在MySQL中转义列名,请使用反引号

`dateadded`

Using quotes turns it into a normal string

使用引号将其转换为普通字符串

'dateadded'