mysql - select statement with where condition (select all or some) -
i have following tables:
images:
imageid userid translated theimage -------------------------------------------- 1 2 1 image1 2 3 0 image2 3 3 0 image3 4 3 0 image4 5 3 1 image5
and translationchains:
imageid sourcelang targetlang ------------------------------------ 1 2 3 2 4 1 3 5 1 4 4 2 5 1 4
now have 2 options: want either choose images wasn't translated specific user in language or choose images user wasn't translated in specific language.
i have following query first option:
"select images.imageid, images.theimage, images.translationrating images images.userid=? , images.translated =0"
and second option have:
"select images.imageid, images.theimage, images.translationrating images, translationchains images.userid=? , images.translated =0 , translationchains.imageid = images.imageid , translationchains.targetlang = ? "
for example if i'll use first query user 3 want result be:
2 3 0 image2 3 3 0 image3 4 3 0 image4
and second query user 3 , targerlang = 1 want result be:
2 3 0 image2 3 3 0 image3
i want combine 2 queries 1 query work in cases (according parameters i'll send)
how can it?
i trying send second parameter (translationchains.targetlang = ?) string " " (empty string) ignore condition didn't work
you may try
first query
select * images userid=3 , translated =0
output:
imageid userid translated theimage 2 3 0 image2 3 3 0 image3 4 3 0 image4
second query
select i.imageid, userid, translated, theimage images inner join translationchains t on t.imageid = i.imageid i.userid=3 , i.translated =0 , t.targetlang = 1
output:
imageid userid translated theimage 2 3 0 image2 3 3 0 image3
the combine:
select i.imageid, userid, translated, theimage images inner join translationchains t on t.imageid = i.imageid i.userid=3 , i.translated =0 , t.targetlang in (select targetlang translationchains ) ^^^^^-------replace 1 or 2 or 3 or let //-- if want change targetlang replace number //--like (select 1 translationchains )
obs: in php when select language put
$sql .= "and t.targetlang = the_id_selected_of_language ";
Comments
Post a Comment