I have two queries that have data that I need in one report.
Query a1:
Ouput data:
Query a2:
Ouput data:
Here is what I did with the two quieres
The output I get is only the data from the left table.
How do I get data from both queries that match the main select statement criteria?
Query a1:
Code:
Select fname, lname,state
from contact
where state = 'TN'
Ouput data:
Code:
fname lname state
Kim Smith TN
Jim Jones TN
Sarah Lewis FL
Joe Wills TN
Query a2:
Code:
Select fname, lname, state
from customer
where state = 'TN'
Ouput data:
Code:
fname lname state
Kim Smith TN
Jim Jones TN
John LONG CA
Tim Brown TN
Here is what I did with the two quieres
Code:
select a1.fname, al.lname,a2.state
from contact
(select fname, lname,state
from contact
where state = 'TN') as a1
left join
(select fname, lname,state
from customer
where state = 'TN') as a2
on a1.state = a2.state
where state = 'TN'
Code:
The expected outcome:
Kim Smith TN
Jim Jones TN
Joe Wills TN
Tim Brown TN