sql - Query Help required for newbie -
sql - Query Help required for newbie -
i have created 3 tables.
tblregion{regionid integer, regionname varchar(100)}, tblcountries{countryid integer, countryname varchar(100), regionid varchar(3)}, tblusrs{userid integer, username varchar(100), prefregion varchar(3), prefcountries varchar(100)}
now info in each table:
tblregion --------- regionid regionname: 1 asia -- 2 africa -- 3 europe -- 4 america tblcountries ------------- countryid countryname regionid: 1 china 1 -- 2 malaysia 1 -- 3 singapore 1 -- 4 afganistan 3 -- 5 uk 3 -- 6 kingdom of spain 3 -- 7 libiya 2 -- 8 kingdom of morocco 2 -- 9 4 -- 10 canada 4 -- 11 united mexican states 4 tblusrs ------- usrid usrname prefregion prefcountries: 1 mike 2 -1 -- 2 john -1 '1,5,9' -- 3 michael -1, '1' -- 4 tango -1 '8,9'
from above info if user passes part 2, both userid 1 & 4 displayed.
i have written query seems thing wrong.
select * tblusers (prefregion = '2') or ('2' in ( select regionid tblcountries, tblusers convert(varchar,tblcountries.countryid) in (tblusers.prefcountries) ) )
the sec part of wherclause (after 'or') subselect makes no sense if sub-subselect right - finding out if has 2 part id has no impact on tblusers selection @ all.
edit: michal making readable :)
perhaps need on line 3 of select:
where (prefregion = '2') , (prefregion in (the rest of subselect) )
sql
Comments
Post a Comment