This Query Dose NOT work in Access 2000
SELECT (Members.First_Name + " " + Members.Last_Name)AS Member,
(SELECT Friend_E_Mail,
FROM Friends,Members WHERE My_E_Mail = ? and Friend_E_Mail <> ?
UNION ALL
SELECT My_E_Mail,FROM Friends,Members
WHERE Friend_E_Mail = ?and My_E_Mail <> ?) AS E_Mail ,
(Members.First_Name) AS Name
FROM Members,Friends
Sample Tables
Members(all VARCHAR) SOME DATA
First_Name Alester Jude Carl Jones
Last_Name A 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 A 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 the "?" are query string parameters that im passing in the "?" i know that works fine.
MY QUESTION IS : i keep getting this error "Operation Not Allowed in Sub Query"
is their a work around query i can use without using a stored procedure or using multiple queries since this needs to be ONE SINGLE QUERY!?
Thanks.
You can´t return more then 1 row in a select subquery. To this case you have to use the CASE expression.
You have to do something like this:
Thys way it will return a row for each friend. You can see that the names of the fields are not so good, try to refactory it. my_e_mais isn´t so representative.