469,949 Members | 2,203 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,949 developers. It's quick & easy.

Multiple join query question

Hi all.

I'm trying to write a query but cant get it to work right.

I have two tables that I wish to join

table: required_books
Columns: class_id, isbn
x | 1
x | 2
y | 1
table: books
columns: isbn, author, title, ... etc (irrelevant)
1 | J. Bloe | Mysql | ...
2 | H. Simpson | Diary | ...
3 | H. Simpson | The life of Bart | ...
What I'm trying to get is books that a particular class hasn't already
So for class_id 'x' , the query would return isbn id of 3, for class_id 'y',
i should get books with book_isbn id's 2 and 3.

This is what i'm trying to do for class_id 'x':
SELECT books.isbn
FROM required_books AS rb
RIGHT OUTER JOIN books ON books.isbn = rb.isbn
WHERE rb.crn_id != 'x' OR rb.isbn IS NULL

Which works when there's only single class entries in required_books table,
like this
x | 1
x | 2

But as soon as you get varying class_id's, it breaks...

I'd really appreciate if someone could give me a hint as to how I should fix
the query so that it works properly. Oh I'm using MySQL v3.23.58 if anybody
wants to know.


Jul 19 '05 #1
0 865

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Ed_No_Spam_Please_Weber | last post: by
5 posts views Thread by rdemyan via AccessMonster.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.