Sql Inner Join/Union

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rogerford
    New Member
    • Feb 2008
    • 5

    Sql Inner Join/Union

    I have two tables tbl_Dropdownlis t and tbl_ListbValues

    tbl_Dropdownlis t has fol. Columns.
    DDLid -PK
    DDLName


    tbl_ListValues has fol. columns.
    ListValueId
    DDlid – FK
    LValue


    On my result set I need DDLname from tbl_Dropdownlis t & LValue associated with DDLName in tbl_ListValues.

    if try a inner join query like "select tbl_Dropdownlis t.DDLName,ListV alues.LValue from tbl_Dropdownlis t inner join tbl_ListValues on tbl_Dropdownlis t.DDLid = tbl_ListValues. DDLid"

    I have 14 LValue(list values) from tbl_ListValues and the same DDLName occuring 14 times for each list values like below:

    DDLName LValue
    OAP GHU
    OAP JHU
    OAP BIN
    OAP DB
    OAP DOD
    OAP DOI
    OAP CL
    OAP LAB
    OAP For
    OAP WS 3.0
    OAP WAR
    OAP CLA
    OAP SP
    OAP SUrf

    if i use a Union Query "Select LValue from ListValues
    Union Select DDLName as LValue
    order by LValue " My result set looks like this

    BIN
    CLA
    CL
    DB
    DOD
    DOI
    For
    GHU
    JHU
    LAB
    OAP-From tbl_Dropdownlis t and rest from tbl_ListValues.
    SP
    SUrf
    WS 3.0
    WAR

    I have to extract this to a datatable. On my datatable i want to have OAP- DDLName from tbl_Dropdownlis t as the first value then followed by the listvalues.

    How can i get a result set where i have to have OAP on the top of the list followed by the list values?

    Union and Inner join Query does not give me the desired result. I appreciate your help on this.

    Thanks
  • Delerna
    Recognized Expert Top Contributor
    • Jan 2008
    • 1134

    #2
    If you post some demo data for each table
    and then a demo result for how you want the
    demo data to look, it will help us understand you better
    just a few lines for each table will do
    and then a complete result for those few lines

    Comment

    • rogerford
      New Member
      • Feb 2008
      • 5

      #3
      Originally posted by Delerna
      If you post some demo data for each table
      and then a demo result for how you want the
      demo data to look, it will help us understand you better
      just a few lines for each table will do
      and then a complete result for those few lines
      I got the answer for my Question.
      I declared a temp table. Inserted into temp table DDLName from tbl_dropdownlis t and ordered them. Inserted into temp table LValue from tbl_ListValues and ordered them. Select * from "temp table name".

      Comment

      Working...