CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2005
    Posts
    3

    Question Sql Join Query Help

    Hey guys, in a pinch with this one. I need assistance trying to figure out this query where I need to join 3 different tables.

    Table 1: xORDERS
    Table 2: xINVENTORY
    Table 3: xSUPPLY

    I'm trying to do a querry to translate two codes I have in xORDERS through a select statement.

    in xORDERS there's the columns INVCD and SUPCD. Each are 6 digit codes, that match up to columns in xINVENTORY and xSUPPLY. In both of those tables, the column is titled xCODE.

    What I want to do is say, take all of the entries in xORDERS, and for every INVCD code, go to xINVENTORY, find that same code and return the value of the column titled xLABEL. Also, for every SUPCD code, go to xSUPPLY, find that same code and return the value of the column titled xLABEL.

    I can get one half of it to work, but it always errors when I try to get the second half.

    I'm really pressed for time on this project, and my only hangup is this query. Any assistance would be awesome.

  2. #2
    Join Date
    Jul 2004
    Location
    Jakarta, Indonesia
    Posts
    596

    Re: Sql Join Query Help

    Code:
    SELECT t1.INVCD, t1.SUPCD, (SELECT t2.xLABEL FROM xINVENTORY AS t2 WHERE t2.xCODE = t1.INVCD) AS xInventory,(SELECT t3.xLABEL FROM xSUPPLY AS t3 WHERE t3.xCODE = t1.SUPCD) AS xSupply
     ORDER BY t1.InVCD
    if it's not working plz post the tables structure

    1st NF - a table should not contain repeating groups.
    2nd NF - any fields that do not depend fully on the primary key should be moved to another table.
    3rd NF - there should be no dependency between non key fields in same table.
    - E. Petroutsos -


    eRiCk

    A collection of "Laku-abis" Ebook, Permanent Residence

    Access Reserved Words, a Classic Form Bug, Access Limitation, Know run Process and the Lock they hold in, Logging User Activity in MSSQL

  3. #3
    Join Date
    May 2005
    Posts
    3

    Re: Sql Join Query Help

    it worked, thanks

  4. #4
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104

    Re: Sql Join Query Help

    dont even need to use reduced result sets:

    select
    xORDERS.name,
    xINVENTORY.name,
    xSUPPLY.name
    from
    xORDERS,
    xINVENTORY,
    xSUPPLY
    where
    xORDERS.inventoryID = xINVENTORY.ID,
    xORDERS.supplyID = xSUPPLY.ID



    do a select * from, if you want to see the full thing.. the where joins all the tables togetehr on their IDs, one row per matching row, from the 3 tables..
    then just 3 columns are picked out
    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured