Skip navigation
Currently Being Moderated

Help with SQL Join Query

May 10, 2012 1:25 PM

I'm just having a bit of troubel getting a Join query correct - I thought it was an Inner Join, but am not getting the results I'd expect.

 

My table structure is:

 

Table : lodges

 

LodgeID (PK)

Lodge

etc

 

Table : nominations

 

NominationID (PK)

Category

LodgeID

Year

 

So I'm trying to use that structure to replicate this page:

 

http://www.safariawards.com/nominees12/

 

ie a list of lodges for each category they are nominated in.

 

The query I've tried looks like this:

 

SELECT nominations.LodgeID, lodges.Lodge, nominations.NominationID, nominations.Category FROM lodges INNER JOIN nominations ON lodges.LodgeID=nominations.NominationID WHERE category='Best Safari Property in Southern Africa' ORDER BY Lodge

 

But is producing this:

 

http://www.safariawards.com/nominees12/southernafrica.php

 

Its the right number of results, but not the right list of lodges - for example British Airwways isn't LodgeID 786

 

If anyone could help out with the right SQL for this that would be much appreciated.

 
Replies
  • Currently Being Moderated
    May 10, 2012 4:35 PM   in reply to johngordon12

    You're joining on the wrong column. Try this:

     

    SELECT nominations.LodgeID, lodges.Lodge, nominations.NominationID, nominations.Category FROM lodges INNER JOIN nominations ON lodges.LodgeID=nominations.LodgeID WHERE category='Best Safari Property in Southern Africa' ORDER BY Lodge

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points