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

Help - SQL and table joins

Status
Not open for further replies.

Decus

Programmer
Oct 11, 2001
20
FR
I have two tables, Books and RelatedBooks , with identical field names, title and author

The RelatedBooks has records that related to the table Books, but not all Books have related books.

I want a list of all books from both the Books table and RelatedBooks table when I specify a criteria such as choosing the a specific subject.

Below is an emample of the SQL statement I'm using.

Select Books.title, Books.author, RelatedBooks.title, RelatedBooks.author

From Books LEFT OUTER JOIN RelatedBooks ON Books.booksID = RelatedBooks.relatedBooksID

WHERE Books.subject = "SQL"


The problem is that I'm only receiving books listed from the Books table and NOT the RelatedBooks table, and I'm receiving duplicate records from the Books table when in some situations I know I should only be receiving just one record.

Can anyone suggest what is wrong with the SQL statement?
I'm using Access 2000.
 
OK, I know why I'm getting duplicate results - I needed to specify an addition condition in the WHERE clause, but I'm still having problems with receiving records from the RelatedBooks table where they match up with books in the Books table
 
Problem solved (or not solved) - it was working fine anyway. Unfortunately there was an incorrect record in the RelatedBooks table which was giving me improper results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top