Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Error - Need help with query

Status
Not open for further replies.

HookEmHorns

Programmer
Dec 17, 2009
27
0
0
US
I am getting the following error and unsure how to resolve it:

Msg 116, Level 16, State 1, Line 1
Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.

My Query:

SELECT * from PatientVisit
WHERE PatientVisitId NOT IN
(SELECT * from PatientVisitResource pvr
JOIN PatientVisit pv on pvr.PatientVisitID = pv.PatientVisitId)

I am essentially trying to write a query that gives me a list of all visits without a Resource. Any insight is appreciated.
 
Please disregard this post. I was able to get my solution:

SELECT
pv.*
FROM
PatientVisit pv
LEFT OUTER JOIN PatientVisitResource pvr ON pvr.PatientVisitID = pv.PatientVisitId
WHERE
pvr.PatientVisitID IS NULL
 
Yes, it's good and better than NOT IN. For NOT IN to work correctly you needed to specify only one field, e.g.

SELECT * from PatientVisit
WHERE PatientVisitId NOT IN(SELECT PatientVisit from PatientVisitResource pvr
JOIN PatientVisit pv on pvr.PatientVisitID = pv.PatientVisitId)

PluralSight Learning Library
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top