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
 Development Tools
 ASP.NET
 Complex SqlDataSource.SelectCommand.

Author  Topic 

davidshq
Posting Yak Master

119 Posts

Posted - 2005-06-10 : 15:38:06
Hi,
I've got two tables. One is called Games and the other GamesPopularity. The Games table includes the following columns: ID, title, description, popularity. The GamesPopularity table includes the following columns: ID, gameID, userID, and popularity.
Lets say user1 visits the site and rates a game with a 10. user2 visits a site and rates the game with an 8. The next time user1 visits the site I want it to display the game but with his rating, and when user2 visits the site I want it to display the game with his rating. Thus the results might look like this:
user1: ID:1 Title: Dodgeball Description: A game Popularity: 10
user2: ID:1 Title: Dodgeball Description: A game Popularity: 8
Here is where my problem comes in. I try an sql statement something like:
"SELECT * FROM Games G LEFT JOIN GamePopularity GP ON G.Popularity=GP.Popularity WHERE ID=" & varID & ""
Great, except that this doesn't know which popularity rating to grab. So, I add in a statement to filter for user:
"SELECT * FROM Games G LEFT JOIN GamePopularity GP ON G.Popularity=GP.Popularity WHERE ID=" & varID & " AND GP.userID=" & varUserName & " AND GP.gameID=" & varID & ""
This would work great except that there is not a Popularity record for every game, so if they pull up a game without a Popularity record in GamePopularity they get no result instead of just getting the Games table result without comining GamePopularity. So I need to somehow tell it if there is no matching GP.userID and GP.gameID to still pull the info. from the Games table. Any ideas?
David.

- http://www.civilwarsearch.com/
- http://www.thehungersite.com/
- http://www.grid.org/

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-06-10 : 16:03:35
Duplicate:

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=50950

Please do not post your question in more than one forum. And if you do, at least link them to each other so that people answering your question no what's going on in the other one.

Tara
Go to Top of Page
   

- Advertisement -