Answer the question
In order to leave comments, you need to log in
How to substitute a value from a field in the same table in a mysql query?
Tell me please.
The table has fields `id`, `date`, `time` and so on.
There is the following query:
delete from `table` where `date` < now() - interval '1' minute
But instead of 1 I need to substitute the value from the `time` field (which is also in the same table).
How to do it right?
I tried different options like:
delete from `table` where `date` < now() - interval `time` minute and so on, but it doesn't work...
Answer the question
In order to leave comments, you need to log in
You can do this with a nested subquery that will select 1 `time` from the same table, according to whatever criteria you like.
I select `time` from entry with id=90210
DELETE FROM `table`
WHERE `date` < NOW() -
INTERVAL
(SELECT `time` FROM `table` WHERE id=90210 LIMIT 0,1)
MINUTE
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question