Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 SQL Join of 2 tables

Author  Topic 

rhoenig
Starting Member

11 Posts

Posted - 2005-01-21 : 21:34:16
I'm having a problem with what seems like a pretty simple join.

I have 2 tables that I would like to get data from. Movietitles and Rentallog

Movietitles has multiple movie titles
Rentallog is a log of all the movietitles rented which is linked to the movietitles table by the movieid(FK)

My query would take the movieid from the movietitles table go to the rentallog table and check to see if that movie is checked out by checking a checkedout field which has an X if it's checked out.

Here is the Select statment I thought was right

Select r.movieid, mt.movietitle, r.checkedout from movietitles mt Left JOIN rentallog r on r.movieid = mt.titleid where r.checkedout <> 'X'

There are 8 records in the Movietitles table
There are 3 records in the Rentallog table (1 of which has an X in the checkedout field)

My query is only returning 2 records (which are in the rentallog table without an X in the checkedout field). I'm not sure what I'm doing wrong. Can someone please help.

Thank you
Robert


Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2005-01-22 : 01:15:01
Are you looking for the movies that ARE checked out? Would that be designated by "r.CheckedOut = 'X'" instead of "r.CheckedOut <> 'X'"

HTH

=================================================================

Our elections are free, it's in the results where eventually we pay. -Bill Stern, sports announcer (1907-1971)
Go to Top of Page
   

- Advertisement -