If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > NOT IN clause problem

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-23-06, 08:38
aspliid aspliid is offline
Registered User
 
Join Date: Sep 2006
Posts: 1
NOT IN clause problem

I'm baffled on this one. I retrieve a full filelist using:
SELECT id, filename FROM files WHERE teacher_users_id=1 ...

now I want to exclude some files:
...AND id NOT IN (4,7)

this works nice and return 12 rows. But when I put the NOT IN clause into a subquery (this subquery returns 4 and 7):

SELECT id, filename FROM files WHERE teacher_users_id = 1 AND
id NOT IN
(SELECT id FROM files f, offers o, student s
WHERE f.teacher_users_id = 1 AND f.id = o.files_id AND
s.users_id = o.student_users_id AND
s.teacher_users_id = f.teacher_users_id AND
s.users_id = 5
)

nothing happens. EXPLAIN SELECT returns this:

1 PRIMARY files ref file_FKIndex1 file_FKIndex1 4 const 29 Using where
2 DEPENDENT SUBQUERY s const PRIMARY,student_FKIndex1,student_FKIndex2 PRIMARY 4 const 1
2 DEPENDENT SUBQUERY f eq_ref PRIMARY,file_FKIndex1 PRIMARY 4 func 1 Using where
2 DEPENDENT SUBQUERY o eq_ref PRIMARY,offers_FKIndex1,offers_FKIndex2 PRIMARY 8 const,phpmp3.f.id 1 Using where; Using index

What's wrong? I'm running on MySQL 4.1.16.

Thx in advance
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On