I'm overlooking something trivial here. This query isn't for any reason in particular other than trying to practice joining two queries. The errors that I get are
Msg 156, Level 15, State 1, Line 10
Incorrect syntax near the keyword 'inner'.
Msg 156, Level 15, State 1, Line 16
Incorrect syntax near the keyword 'as'.
And the query is
select t.countyName, x.countyName
from
(
SELECT DISTINCT Patient.patientid, tblStateCounties.countyName, Patient.countyCode
FROM Patient INNER JOIN
tblStateCounties ON Patient.stateCode = tblStateCounties.stateCode AND Patient.countyCode = tblStateCounties.countyCode
WHERE (Patient.patientage > 80)
)
inner join
(
SELECT DISTINCT Patient.patientid, tblStateCounties.countyName, Patient.countyCode
FROM Patient INNER JOIN
tblStateCounties ON Patient.stateCode = tblStateCounties.stateCode AND Patient.countyCode = tblStateCounties.countyCode
WHERE (Patient.patientage < 80)
) as x on t.countyname=x.countyname
you forgot use alias in the first subquery
.
select t.countyName, x.countyName
from
(
SELECT DISTINCT Patient.patientid, tblStateCounties.countyName, Patient.countyCode
FROM Patient
INNER JOIN tblStateCounties ON Patient.stateCode = tblStateCounties.stateCode
AND Patient.countyCode = tblStateCounties.countyCode
WHERE (Patient.patientage > 80)
) rsT
inner join
(
SELECT DISTINCT Patient.patientid, tblStateCounties.countyName, Patient.countyCode
FROM Patient
INNER JOIN tblStateCounties ON Patient.stateCode = tblStateCounties.stateCode
AND Patient.countyCode = tblStateCounties.countyCode
WHERE (Patient.patientage < 80)
) rsX on rsT.countyname=rsX.countyname
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With