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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL query will not work with subquery 2

Status
Not open for further replies.

TNN

Programmer
Sep 13, 2000
417
US
Can someone please tell me why this SQL statement will not work???

SELECT FNAME,MIDDLE,LNAME
FROM BASSPERS
WHERE BASSPERS.EMPNO=(SELECT DISTINCT EMPNO FROM EMPEARNPERWAGE
WHERE PYRLNO=(SELECT LASTPYRLNO FROM LASTPYRLNO))

LASTPYRLNO is a field in a table LASTPYRLNO.

The subquery (SELECT DISTINCT..... works good by itself and returns a single column of EMPNO's.

TNN, Tom


TOM
 
You need semicolons at the end of the subqueries.

For the EMPNO criteria, you should use the In operator instead of = because you are getting multiple EMPNOs back.

For the PYRLNO criteria, if there are multiple LASTPYRLNO's, use Max() or something in the subquery to return a single value.
 
Good points from JonFer. I don't think you need the semicolons in subqueries as I have never used them.

Duane
MS Access MVP
 
JonFer,
Using the "IN" operator worked. What is it then, you use the = sign only when the resultant recordset is one record with a single field????

There is only a single LASTPYRLNO.

Thank You very much, TNN,Tom

PS: The semicolons were not necessary.



TOM
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top