I have a table called orders
with (a.o.) columns sid
and q1_requested_by
.
The sid
column contains a unique id number, incrementing with every new input.
Every now and then there is an input in column q1_requested_by
with the value ORDERS PROCESSED
.
I want to select everything from the table which falls in between the latest ÒRDERS PROCESSED
input and the latest but one ORDERS PROCESSED
input.
I've tried the following, which doesn't work. It selects nothing.
SELECT * FROM orders
WHERE sid < (SELECT max(sid) FROM orders
WHERE q1_requested_by = 'ORDERS PROCESSED')
AND sid > (SELECT TOP 2 sid FROM orders
WHERE q1_requested_by = 'ORDERS PROCESSED'
ORDER BY sid DESC)
ORDER BY sid DESC
How could I solve this?