sql - "Union Operation not allowed in sub query" is there a way to fix this in one single query? -
this query dose not work in access 2000
select (members.first_name + " " + members.last_name)as member, (select friend_e_mail, friends,members my_e_mail = ? , friend_e_mail <> ? union select my_e_mail,from friends,members friend_e_mail = ?and my_e_mail <> ?) e_mail , (members.first_name) name members,friends
sample tables
members(all varchar) data first_name alester jude carl jones last_name b c j friends(all varchar) my_e_mail alester@lam.com alester@lam.com alester@lam.com friend_e_mail jude@lam.com carl@lam.com jones@lam.com
desired output if ("?" in above query is: jones@lam.com)
+--------------+-----------+------------+ |member |e_mail | name | +---------------------------------------+ alester alester@lam.com alester
desired output if("?" in above query is: alester@lam.com)
+--------------+-----------+------------+ |member |e_mail | name | +---------------------------------------+ jude b jude@lam.com jude carl c carl@lam.com carl jones j jones@lam.com jones
ps "?" query string parameters im passing in "?" know works fine.
my question : keep getting error "operation not allowed in sub query"
is work around query can use without using stored procedure or using multiple queries since needs 1 single query!?
thanks.
you can´t return more 1 row in select subquery. case have use case expression.
you have this:
select (m.first_name + " " + m.last_name) member, case when f1.my_email null f2.my_e_mail else f1.friend_email end email, m.first_name name members m left outer join friends f1 on m.email = f1.my_e_mail , f1.friend_e_mail = ? left outer join friends f2 on m.email = f2.friend_e_mail , f2.my_e_mail = ?;
thys way return row each friend. can see names of fields not good, try refactory it. my_e_mais isn´t representative.
Comments
Post a Comment