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
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Problem in Join

Problem in Join

Scheduled Pinned Locked Moved Database
helptutorial
2 Posts 2 Posters 0 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.
  • B Offline
    B Offline
    banker_kiran
    wrote on last edited by
    #1

    Hi, I have three table 1. EmpMst 2. RefDef 3. RefValue Empmst contains EmpCode, EmpName, DesigCode,DeptCode RefDef contains Definitions like department, designation etc. RefValue stores def_code from RefDef table and also stores uniqueid of value and description. Means Designation and Department both are stored in on table under same column. now i want to get result like EmpCode, EmpName, Designation, Department. Problem is how to get unique records.

    kiranbanker

    P 1 Reply Last reply
    0
    • B banker_kiran

      Hi, I have three table 1. EmpMst 2. RefDef 3. RefValue Empmst contains EmpCode, EmpName, DesigCode,DeptCode RefDef contains Definitions like department, designation etc. RefValue stores def_code from RefDef table and also stores uniqueid of value and description. Means Designation and Department both are stored in on table under same column. now i want to get result like EmpCode, EmpName, Designation, Department. Problem is how to get unique records.

      kiranbanker

      P Offline
      P Offline
      pmarfleet
      wrote on last edited by
      #2

      You would want a query like

      select empmst.empcode, empmst.empname, refvalue_1.description as designation, ref_value_2.description as department
      from empmst inner join refvalue refvalue_1
      on empmst.desigcode = refvalue_1.value
      inner join refvalue refvalue_2
      on empmst.deptcode = refvalue_2.value

      This assumes that the values in field RefValue.value are unique to the table. If they are not, you would have to filter the records in refvalue_1 and refvalue_2 by the appropriate def_code. I'm not sure why you are getting duplicate records though.

      Paul Marfleet

      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