I have to read a set of rows from a table(say A) containing a unique id for each row (say id_value).
Now using this id_value i have to get rows from another table (say B).
i am using java so my code is:
ResultSet rs= [ Code to get rows from table A ] ;
while(rs.next())
{
ResultSet rs2= [Code to get rows from table B using the id_value from table A using rs.getString("id_value");];
}
The above query if ofcourse slow as the number of rows can be more than 500 at a time in table A.
Does anybody knows a better and fast solution to this problem or how to do this in a single query ??
You should read up on joins in SQL: http://en.wikipedia.org/wiki/Join_(SQL)
You want to do something along these lines:
It would be easier to help you if you had actual queries, though.