Cory Nelson wrote:
Hello folks.
I currently have a table:
create table t_gloss(entryid integer, type integer, value text);
and am running this SQL on it:
select entryid,type from t_gloss where value=?;
then for each row returned (type is type==0?1:0 from above row, and
entryid is the same):
select value from t_gloss where entryid=? and type=? order by value;
This already runs nice and speedy due to indexes, but I am wondering
if it could be combined into one query for further efficiency. Any
ideas?
Cory,
I think this should do what you want in a single query.
select e1.value as value
from t_gloss as e1 join t_gloss as e2
on e1.entryid = e2.entryid
and e1.type = case e2.type when 0 then 1 else 0 end
where e2.value = ?
order by value
HTH
Dennis Cote