java - Search a table with the result of another search in servlet -
i have table table1 2 fields id , shift , table table2 3 fields id, name, surname. field id same primary key in both tables.
in servlet want select id's have shift != noon. write
resultset rs = stmt.executequery("select id table1 shifts!=noon");
so have gather records in rs. now, how can search through second table in order select records id's found in 1st look?
you need join:
resultset rs = stmt.executequery("select t2.* table1 t1 join table2 t2 on t1.id = t2.id t1.shifts <> 'noon'");
look here:
http://www.w3schools.com/sql/sql_join.asp
also need enclose strings noon inside single quotes 'noon', , best use <>
instead of !=
standard sql
, more compatible other databases.
Comments
Post a Comment