In MySQL I am trying to select rows from a table that have a lock_dt older than 10 hours. How can I write this sql statement properly?
select phone from table where ((now() - lock_dt) < 10 hours)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Using intervals is pretty handy. Also, I try to isolate the column so an eventual index can be used (sometimes, the RDBMS don’t know how to use an index with NOW() – lock_dt, even if there’s an index on lock_dt).
Also, the description of your problem contradicts your query.
NOW() - lock_dt < 10 hoursmeans the interval is less than 10 hours. That’s what my query do. You have to change > to < if you want more than 10 hours.