SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Guru
    Join Date
    May 2012
    Posts
    996
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post Need help for two tables

    Hi i need some help on this, how can i join this two tables to display all the records even the first table has no match in second table and only to display one company image..is this possible? I tried to use the inner join but the image is displaying 3 times because i have match in second table with 3 7's,but i cannot display the image even it is not match in second table.

    can you help me on this please

    Thank you in advance.


    firsttble

    Code:
    compID      empCompName                      companyimage
      1             universalpicture                       image
    
      7              Pixelite                                 image
    
       8             Vanchour                              image
    secondtable
    Code:
      compID                  Address                  
        7                          Texas
    
        7                          Sweeden
    
        7                          Mexico

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,016
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    use a LEFT OUTER JOIN with firsttble as the left table
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Guru
    Join Date
    May 2012
    Posts
    996
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi thank you for the reply...but it will only display one address if the second table match to the first table.

    Code:
         select frst.*,scnd.*
                              from firsttable frst right outer join
                              scnd secondtable
                              on frst.compid = scnd.compID

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,016
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    i suggested a left outer join

    you wrote a right outer join

    why?
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Guru
    Join Date
    May 2012
    Posts
    996
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi sorry for that typo it must be left, yes i already tried the left outer join...it will only return one address.

  6. #6
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,016
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    please show your real query and your real tables, not the fake "firsttable" and "scnd"
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  7. #7
    SitePoint Guru
    Join Date
    May 2012
    Posts
    996
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,Thank you...it's okay now


Bookmarks

Posting Permissions

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