 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Tasiek Guest
|
Posted: Fri Nov 05, 2004 8:55 pm Post subject: Problem with simple SQL query :/ |
|
|
I cant handle simple query :/
I have tables
Books(ISBN, Author, Title) ,
Readers(Pin, Name, LastName)
Borrows(Id , ISBN, Pin)
As you can see in borrows are ISBN borrowed book and pin reader which
borrowed that book.
And now i want choose that books which are not borrowed.
SELECT Books.ISBN, Books.Author, Books.Ttitle FROM Books, Borrows
WHERE Books.ISBN <> Borrows.ISBN
It didnt work, i dont know why
Plz help.
Tasiek
|
|
| Back to top |
|
 |
Andy Flowers Guest
|
Posted: Fri Nov 05, 2004 9:16 pm Post subject: Re: Problem with simple SQL query :/ |
|
|
Try this one
SELECT Books.isbn, Books.author, Books.title
FROM Books
WHERE Books.isbn NOT IN (select isbn from borrows);
"Tasiek" <tasiekk (AT) tlen (DOT) pl> wrote
| Quote: | I cant handle simple query :/
I have tables
Books(ISBN, Author, Title) ,
Readers(Pin, Name, LastName)
Borrows(Id , ISBN, Pin)
As you can see in borrows are ISBN borrowed book and pin reader which
borrowed that book.
And now i want choose that books which are not borrowed.
SELECT Books.ISBN, Books.Author, Books.Ttitle FROM Books, Borrows
WHERE Books.ISBN <> Borrows.ISBN
It didnt work, i dont know why
Plz help.
Tasiek
|
|
|
| Back to top |
|
 |
Croaker Guest
|
Posted: Fri Nov 05, 2004 9:22 pm Post subject: Re: Problem with simple SQL query :/ |
|
|
"Tasiek" <tasiekk (AT) tlen (DOT) pl> wrote
| Quote: | I cant handle simple query :/
I have tables
Books(ISBN, Author, Title) ,
Readers(Pin, Name, LastName)
Borrows(Id , ISBN, Pin)
[...]
SELECT Books.ISBN, Books.Author, Books.Ttitle FROM Books, Borrows
WHERE Books.ISBN <> Borrows.ISBN
|
SELECT
Books.ISBN, Books.Author, Books.Ttitle
FROM
Books
WHERE
NOT EXISTS
(
SELECT
Id
FROM
Borrows
WHERE
Borrows.ISDN = Books.ISDN
)
|
|
| Back to top |
|
 |
Tasiek Guest
|
Posted: Sat Nov 06, 2004 1:46 am Post subject: Re: Problem with simple SQL query :/ |
|
|
and one more .... i dont have subquerias :/
Tasiek
|
|
| Back to top |
|
 |
Christian Kalkhoff Guest
|
Posted: Sun Nov 07, 2004 12:12 pm Post subject: Re: Problem with simple SQL query :/ |
|
|
Hi Tasiek,
On Fri, 05 Nov 2004 21:55:48 +0100, Tasiek wrote:
| Quote: | I cant handle simple query :/
I have tables
Books(ISBN, Author, Title) ,
Readers(Pin, Name, LastName)
Borrows(Id , ISBN, Pin)
As you can see in borrows are ISBN borrowed book and pin reader which
borrowed that book.
And now i want choose that books which are not borrowed. SELECT
Books.ISBN, Books.Author, Books.Ttitle FROM Books, Borrows WHERE
Books.ISBN <> Borrows.ISBN
As you mentioned you have no subselects i guess you use that mysql thingy. |
:)
I guess you can solve your problem using a JOIN on the tables. See the
statement below, i havent tested it, but it should work (almost).
SELECT B.ISBN, B.Author, B.Title FROM Books B LEFT JOIN Borrows BR ON
B.ISBN = BR.ISBN WHERE BR.ISBN IS NULL
Hope that helps and works. :)
Christian
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|