I would like to write an SQL query which uses results from previous one.
For example – I have a table Orders with fields: order_id, date and value. I need to get all dates from column date where value is larger than 5:
SELECT date FROM Orders WHERE value > 5;
Then I need to return all values for dates, which are +2 days from the returned ones. Is it possible to write short query without using LOOP statement?
Here is an example table:
I am expecting to get the result:
Advertisement
Answer
his will give you what you need.
select date, value from Orders where date in ( SELECT date + INTERVAL 5 DAY as date FROM Orders WHERE value > 100; )