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

Problem with using NOT IN

Status
Not open for further replies.

woooinred

Programmer
May 8, 2005
4
US
table 'loan':
+--------+
| loanID |
+--------+
| 1 |
| 2 |
| 5 |
| 10 |
| 15 |
+--------+

table 'commitmentAssigned':
+--------------+--------+
| commitmentID | loanID |
+--------------+--------+
| 8 | 1 |
| 9 | 1 |
| 9 | 10 |
+--------------+--------+


I run this query:
select * from loan WHERE loanID NOT IN ("SELECT loanID from commitmentAssign WHERE commitmentID = 9 ");

and hoping to see a return set with loanID = 2, 5, 15 but instead, it gives me:

+--------+
| loanID |
+--------+
| 1 |
| 2 |
| 5 |
| 10 |
| 15 |
+--------+

Can any1 help correcting my query?? THANKS in advance!

 
I didn't include the double quote at first, and this is what I got:
ERROR 1064: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT loanID from commitmentAssign WHERE commitmentID =8)' at
 
You are damn right. 4.0.22 is what I am having.
Any idea to do what I am looking for with this release?
 
you're in luck, eh

not all subquery scenarios have such a convenient workaround --
Code:
select loan.loadID
  from loan 
left outer
  join commitmentAssign
    on loan.loadID
     = commitmentAssign.loadID 
   and commitmentAssign.commitmentID = 9
 where commitmentAssign.loadID is null

rudy | r937.com | Ask the Expert | Premium SQL Articles
SQL for Database-Driven Web Sites (next course starts May 8 2005)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top