Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. SQL query: Get correspondence descriptions instead foreign key IDs. Is that possible ?

SQL query: Get correspondence descriptions instead foreign key IDs. Is that possible ?

Scheduled Pinned Locked Moved Database
databasesharepointquestion
2 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sdancer75
    wrote on last edited by
    #1

    Hi, I have 4 tables in a cascading mode like this : 1)Countries --> 2)Chapionships --> 3) Teams --> 4) Coupons Coupons table has 2 IDs (HomeTeamID and HostTeamID) that points to the Teams table. It has also IDs for the tables (Countries and Chapionships) All I want is to select the appropriate records from the Coupons Table, but instead of the foreing keys IDs I want the correspondence descriptions that these keys shows from their tables (ie Countries, Chapionships and Teams). Is that possible ? All I did until now is the query SELECT * FROM Coupons LEFT JOIN (Countries, Chapionships, Teams) ON (Countries.CountryID=Coupons.CountryID AND Chapionships.ChapionshipID=Coupons.ChapionshipID AND ( Teams.TeamID=Coupons.HomeTeamID OR Teams.TeamID=Coupons.HostTeamID)) Where Date='2009-07-31' order by Time Asc; but I get double rows for each record since there is an OR clause inside the ON. Any better solution ? Regards

    sdancer75

    B 1 Reply Last reply
    0
    • S sdancer75

      Hi, I have 4 tables in a cascading mode like this : 1)Countries --> 2)Chapionships --> 3) Teams --> 4) Coupons Coupons table has 2 IDs (HomeTeamID and HostTeamID) that points to the Teams table. It has also IDs for the tables (Countries and Chapionships) All I want is to select the appropriate records from the Coupons Table, but instead of the foreing keys IDs I want the correspondence descriptions that these keys shows from their tables (ie Countries, Chapionships and Teams). Is that possible ? All I did until now is the query SELECT * FROM Coupons LEFT JOIN (Countries, Chapionships, Teams) ON (Countries.CountryID=Coupons.CountryID AND Chapionships.ChapionshipID=Coupons.ChapionshipID AND ( Teams.TeamID=Coupons.HomeTeamID OR Teams.TeamID=Coupons.HostTeamID)) Where Date='2009-07-31' order by Time Asc; but I get double rows for each record since there is an OR clause inside the ON. Any better solution ? Regards

      sdancer75

      B Offline
      B Offline
      Blue_Boy
      wrote on last edited by
      #2

      Use distinct or try to group.


      I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups