I would use a query with a WHERE field, take a look at this link which will explain you how to get it done:
http://www.w3schools.com/sql/sql_where.asp[
^]
Then with the resultset you can loop and decide what to do.
I'm not sure if that is what you need, but it's what I understood.
Good luck.