Help combining 3 queries into one (SQL)

  • Thread starter Thread starter lillan
  • Start date Start date
L

lillan

I have 3 queries



1. select tbl1.a, tbl1.b from tbl1 where tbl1.b='xxx'



2. select tbl2.a, tbl2.b from tbl2 where tbl2.b='xxx'



and then I want the result to be queried in question 3



3. select tbl1.a, tbl1.b, tbl2.a, tbl2.b from tbl1, tbl2 where
tbl1.a=tbl2.a



I have tried all possible ways but I now need help.
 
Hi,


With Jet 4.0, if all the name are valid (no need to use [ ] :


SELECT P.a, P.b, Q.a, Q.b
FROM ( SELECT a, b FROM tbl1 WHERE b="xxx") AS P
INNER JOIN
( SELECT a, b FROM tbl2 WHERE b="xxx") AS Q
ON P.a=Q.a



With MS SQL Server, you would have to further alias P.a, P.b, Q.a and
Q.b since x.y in not a valid name, so only y is taken, and that makes the
output "a" and "b" duplicated output, an invalid statement.


Hoping it may help,
Vanderghast, Access MVP
 
Back
Top