mysql - sql union with not in condition -
i have query union of multiple selections based on condition. problem "and" section being applied last selection, want apply whole selection (all unions)
select * (select con.id_contact v,substr(concat(ifnull(con.firstname,''),ifnull(con.lastname,'')),1,4) s0, null s1, null s2 contact con, fu_rec_group_link g con.id_contact = g.id_rec , id_group=125801) tbl244295 1=1 union select * (select con.id_contact v,substr(concat(ifnull(con.firstname,''),ifnull(con.lastname,'')),1,4) s0, null s1, null s2 contact con, fu_rec_group_link g con.id_contact = g.id_rec , id_group=125803) tbl244296 1=1 union select * (select con.id_contact v,substr(concat(ifnull(con.firstname,''),ifnull(con.lastname,'')),1,4) s0, null s1, null s2 contact con, fu_rec_group_link g con.id_contact = g.id_rec , id_group=126270) tbl244297 1=1 , v not in (select v (select * (select con.id_contact v,substr(concat(ifnull(con.firstname,''),ifnull(con.lastname,'')),1,4) s0, null s1, null s2 contact con id_user=11944 , unregistered not null) tbl244299 1=1) tblminus )
do unions in derived table, put where outside it:
select * ( select ... union select ... ) dt dt.col ...
Comments
Post a Comment