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
 General SQL Server Forums
 New to SQL Server Programming
 Help with inner joins

Author  Topic 

MartFer
Starting Member

1 Post

Posted - 2009-05-18 : 06:34:23
Hi! I am new to sql and am having a little trouble with a select query. I have a table named "content" where I have all my pieces of content, their titles, authors, etc. I have a table of "users" and then a table of "favourites" where I have the contentID and the userID pairs of favourite contents. I am trying to select the information of the favourite contents of the logged in user. I tried using inner joins, but there is a part towards thee end where I have to join the favourites table to the users, and it is not working. Here goes:

"SELECT * FROM ([NL_LMS_BIB_contents]
INNER JOIN NL_LMS_BIB_topics ON NL_LMS_BIB_contents.topicID = NL_LMS_BIB_topics.topicID)
INNER JOIN NL_LMS_BIB_favourites on NL_LMS_BIB_contents.contentID = NL_LMS_BIB_favourites.contentID
INNERJOIN NL_LMS_BIB_users ON NL_LMS_BIB_favourites.userID = NL_LMS_BIB_users.userID
WHERE NL_LMS_BIB_users.Login = @login"

@login is a session parameter from asp.net which returns the name of the loggged in user, this part is working. The part I am having trouble with is when I am comparing the userID in the table users and with the userID in the table favourites.

Any suggestions please?
Thanks a lot,
Marta

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-05-18 : 06:38:35
quote:
Originally posted by MartFer

The part I am having trouble with is when I am comparing the userID in the table users and with the userID in the table favourites.




What is the trouble you are having? The UserID exists in both the tables right? Can you please explain it more clearly so that a solution can be provided?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-05-19 : 10:25:56
whats the problem you're having? does both the users and favourites tables have 1 to 1 relationship? also does all users have records in both?are you looking for all users regardless of their presence in favourites?
Go to Top of Page
   

- Advertisement -