sql query to incrementally modify where condition until result contains what is required

Posted by iamrohitbanga on Stack Overflow See other posts from Stack Overflow or by iamrohitbanga
Published on 2010-05-16T05:11:41Z Indexed on 2010/05/16 5:20 UTC
Read the original article Hit count: 513

Filed under:
|
|

I need an sql query to select some items from a table based on some condition which is based on a category field. As an example consider a list of people and I fetch the people from a particular age group from the database. I want to check if the result contains at least one result from each of a number of categories. If not I want to modify the age group by extending it and check the results again. This is repeated until I get an age group for which one result is present for each category. Right now i am doing this by analyzing the results and modifying the sql query. So a number of sql select queries are sent. What is the most efficient way of doing this? I am invoking the select queries from a java program using jdbc. I am using mysql database.

© Stack Overflow or respective owner

Related posts about mysql

Related posts about java