I can do this in script, but I know this must be easily possible in MySQL. You know how a bank statement will put a little asterisk next to checks whose numbers are out of order? This is exactly what I want to be able to do.
Assuming a table with the usual id
pkey but also a checkno
integer. I want to return three columns: checkno
, id
, and outoforder
which will be either a blank string or an asterisk:
SELECT t1.checkno, t1.id, outoforder '' FROM table t1 ORDER BY t1.checkno
How would I modify this SQL to do that? I'm thinking a subquery like (SELECT t2.id FROM table t2 WHERE t2.checkno = t1.checkno - 1)
but with some MySQL function thrown on top. Incidentally I tried this type of subquery on my actual table and the query just never returns.