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. General Programming
  3. Visual Basic
  4. Join Tables

Join Tables

Scheduled Pinned Locked Moved Visual Basic
questiondatabase
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.
  • G Offline
    G Offline
    Greeky
    wrote on last edited by
    #1

    Imagine two table One Table (ForeignCurrency) FC_ID FC_TYPE 1 USD 2 EUR 3 YTL Other table (Rates) FCV_ID FCV_RateIN FCV_RateOUT FCV_DATE 1 1 1 10/13/2005 2 1.345 1.346 10/13/2005 3 1.651 1.654 10/13/2005 I need to join two table in a one query. I do this so Select FC.FC_TYPE,ISNULL(FCV_RateIN,1) FCV_RateIN,ISNULL(FCV_RateOut,1) FCV_RateOut from ForeignCurrency FC LEFT OUTER JOIN Rates R ON FC.FC_ID=R.FCV_ID WHERE FCV_Date='10/13/2005' This give me result as i want. But when i need 10/14/2005 rates it give me empty result set , but i expect FCV_TYPE FCV_RateIn FCV_RateOUT YTL 1 1 USD 1 1 EUR 1 1 How can i re-write code ?

    Q 1 Reply Last reply
    0
    • G Greeky

      Imagine two table One Table (ForeignCurrency) FC_ID FC_TYPE 1 USD 2 EUR 3 YTL Other table (Rates) FCV_ID FCV_RateIN FCV_RateOUT FCV_DATE 1 1 1 10/13/2005 2 1.345 1.346 10/13/2005 3 1.651 1.654 10/13/2005 I need to join two table in a one query. I do this so Select FC.FC_TYPE,ISNULL(FCV_RateIN,1) FCV_RateIN,ISNULL(FCV_RateOut,1) FCV_RateOut from ForeignCurrency FC LEFT OUTER JOIN Rates R ON FC.FC_ID=R.FCV_ID WHERE FCV_Date='10/13/2005' This give me result as i want. But when i need 10/14/2005 rates it give me empty result set , but i expect FCV_TYPE FCV_RateIn FCV_RateOUT YTL 1 1 USD 1 1 EUR 1 1 How can i re-write code ?

      Q Offline
      Q Offline
      Qhalis
      wrote on last edited by
      #2

      It looks like a misunderstanding of how the join works. The SQL Engine performs a select on the two tables using the join. The 'left outer' part ensures that if there are entries in the ForeignCurrency table that do not have corresponding entries in the Rates table, then they will still be shown. e.g Add a new entry to the ForeignCurrency table 4 IEP SELECT FC.FC_TYPE ,ISNULL(FCV_RateIN,1) FCV_RateIN ,ISNULL(FCV_RateOut,1) FCV_RateOut FROM ForeignCurrency FC LEFT OUTER JOIN Rates R ON FC.FC_ID=R.FCV_ID will give FC_TYPE FCV_RateIN FCV_RateOut USD 1 1 EUR 1.345 1.345 YTL 1.651 1.654 IEP 1 1 AFTER the join is performed the WHERE criteria are applied. Thus we check through the resultset for the FCV_Date='10/13/2005' (This is all conceptual - in practice the engine may optimize but it ACTS as if the steps happen in this order) For 10/13/2005 all the rows in your test data match, so we are good For 10/14/2005, no rows match so you get an empty set. hth Alan.

      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