----------
User
----------
user_ID(pk)
UserEmail
----------
Employer1
----------
Emp1ID(pk)
Emp1NO
----------
Employer2
----------
Emp2ID(pk)
Emp2NO
----------
Pr
You can only return one column from your subquery. If you just want both the employee ID and manager ID consider a union query as your subquery:
emp.Emp2NO IN
(select ProjEmpID from project
union
select ProjEmpMGRID from project)
or rewriting to use two IN queries with separate subqueries for each.
emp.Emp2NO IN
(select ProjEmpID from project) or (select ProjEmpMGRID from project)
Hope you will understant why it should be so. u can put a mail to me at gnmsr@ap.nic.in
Ok i will expalin. Emp1NO is one value chcked with every value in the list of values return by a single column values where as ur query returns a matrix of many(no. of rows) X 2
I would recommend not using the IN statement. Use EXISTS instead.
http://www.techonthenet.com/sql/exists.php
Example #1
Eric Hauser is correct - you can't specify two columns in SELECT contained in an IN clause to one column outside.
That said, I re-wrote your query so you don't need to use UNIONs at all:
SELECT DISTINCT u.user_email
FROM USERS u
JOIN EMPLOYER e ON u.user_id IN (e.emp1id, e.emp2id)
JOIN PROJECT p ON e.emp1no IN (p.projempid, p.projempmgrid)
OR e.emp2no IN (p.projempid, p.projempmgrid)
I also changed the query to use ANSI-92 JOIN syntax - your original uses ANSI-89.