which one is a faster/better sql practice?

Posted by artsince on Stack Overflow See other posts from Stack Overflow or by artsince
Published on 2010-03-25T12:42:53Z Indexed on 2010/03/25 12:43 UTC
Read the original article Hit count: 118

Filed under:
|

Suppose I have a 2 column table (id, flag) and id is sequential. I expect this table to contain a lot of records. I want to periodically select the first row not flagged and update it. Some of the records on the way may have already been flagged, so I want to skip them.

Does it make more sense if I store the last id I flagged and use it in my select statement, like

select * from mytable where id > my_last_id order by id asc limit 1

or simply get the first unflagged row, like:

select * from mytable where flagged = 'F' order by id asc limit 1

Thank you!

© Stack Overflow or respective owner

Related posts about sql

Related posts about query-optimization