AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Problem with simple SQL query :/

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java and Databases
View previous topic :: View next topic  
Author Message
Tasiek
Guest





PostPosted: Fri Nov 05, 2004 8:55 pm    Post subject: Problem with simple SQL query :/ Reply with 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
Andy Flowers
Guest





PostPosted: Fri Nov 05, 2004 9:16 pm    Post subject: Re: Problem with simple SQL query :/ Reply with quote



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





PostPosted: Fri Nov 05, 2004 9:22 pm    Post subject: Re: Problem with simple SQL query :/ Reply with quote



"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





PostPosted: Sat Nov 06, 2004 1:46 am    Post subject: Re: Problem with simple SQL query :/ Reply with quote

and one more .... i dont have subquerias :/

Tasiek


Back to top
Christian Kalkhoff
Guest





PostPosted: Sun Nov 07, 2004 12:12 pm    Post subject: Re: Problem with simple SQL query :/ Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java and Databases All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.