Link to home
Start Free TrialLog in
Avatar of pmnox
pmnox

asked on

Can I use union with sql subqueries?

Can I use union with sql subqueries?

SELECT * FROM TABLE WHERE 1 = (SELECT 1 FROM msysaccessobjects UNION SELECT 1 FROM msysaccessobjects)

I tried to use union with sql subqueries. However I get an error when I try to compile this sql query. Does UNION work with sql subqueries?
Avatar of Thomasian
Thomasian
Flag of Philippines image

Yes, you can.

But since your subquery will return more than 1 value, you need to use IN instead of =

SELECT * FROM TABLE WHERE 1 IN (SELECT 1 FROM msysaccessobjects UNION SELECT 1 FROM msysaccessobjects)
ASKER CERTIFIED SOLUTION
Avatar of Thomasian
Thomasian
Flag of Philippines image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of peter57r
Can you explain the point of the query.

It won't work with a union in the subquery but even if it did , the query would be just the same as one which just says:
Select * from table
Avatar of pmnox
pmnox

ASKER

Thx for help.