Let's say we have fields: id | content | updateTime | creationTime
When insertion done both updateTime and creationTime get filled with current time. On update only updateTime field get changed. When I need to find all data created on '2012-06-28' I simply use:
SELECT id, content FROM tbl WHERE creationTime LIKE '2012-06-28%'`
But to get all data that was updated excluding created data I need to use something like this:
SELECT id, content FROM tbl WHERE creationTime LIKE '2012-06-28%' AND creationTime != updateTime
This can't work, obviously. Though I could find all updated data by comparing values of two 'time' collumns inside php, I'd still love to do it inside query.
UPD: Well, it turns out that I was absolutely unaware that sql allows not only compare value of a field with a given variable, number... but also it can compare value of one field with another.
Use <>
instead !=
(that isn't compatible with some DMBS)
So
SELECT id, content
FROM tbl
WHERE creationTime LIKE '2012-06-28%' AND creationTime <> updateTime
If you want some documentation you can find here
However, your query have to work properly with !=
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With