Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Posts
    358
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Join three tables in a SQL statement.

    Dear,

    i have 3 tables : Level1, Level2 and Level3
    Structure:
    Level1
    =====
    L1Code L1Name

    Level2
    =====
    L1Code L2Code L2Name

    Level3
    =====
    L1Code L2Code L3Code L3Name


    How to list the records like
    Code:
    L1
    ==
       L2
       ---
          - L3
    
    L1
    ==
       L2
       ---
          - L3
          - L3
       L2
       ---
          - No Record.
    
    
    L1
    ==
       L2
       ---
          - No Record.
       L2
       ---
          - No Record.
    But in the Level2, they might not have any record(Level3)

    I can make it if i use 2 SQL and with 2 loops
    But what i facing is how to make it in a SQL Statement???
    Thanks.
    =====================================================
    From NinjaTurtle
    ++http://ohmygoh.blogspot.com|http://technology.ohmygoh.com++

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    I think it is something like this (not positive):
    Code:
    SELECT   Level1.L1Code,
                 Level1.L1Name,
                 Level2.L2Code,
                 Level2.L2Name,
                 Level3.L3Code,
                 Level3.L3Name
    FROM     Level1
    LEFT OUTER JOIN Level2 ON Level1.L1Code = Level2.L2Code
    LEFT OUTER JOIN Level3 ON Level2.L2Code = Level3.L3Code
    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Posts
    358
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Its work... TQ
    Thanks.
    =====================================================
    From NinjaTurtle
    ++http://ohmygoh.blogspot.com|http://technology.ohmygoh.com++


  •  

    Posting Permissions

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