Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

Simple SQL Question on Joins

  • 06-11-2008 05:51PM
    #1
    Closed Accounts Posts: 2,268 ✭✭✭


    How do I join 2 Tables on JOINID where
    Table 1 has 5 records and
    Table 2 has 500 records and I want to get 500 records

    I want the fields from Table1 to be null in the Query but a right Outer Join is giving me 2500 records and an Inner Join is giving me 5 records !!!

    Left Outer Join Gives 5 records
    Join Gives 5 records


    What do I do?


Comments

  • Registered Users, Registered Users 2 Posts: 868 ✭✭✭brianmc


    How do I join 2 Tables on JOINID where
    Table 1 has 5 records and
    Table 2 has 500 records and I want to get 500 records

    I want the fields from Table1 to be null in the Query but a right Outer Join is giving me 2500 records and an Inner Join is giving me 5 records !!!

    Left Outer Join Gives 5 records
    Join Gives 5 records


    What do I do?


    Reverse the tables and LEFT OUTER to Table 1?


  • Registered Users, Registered Users 2 Posts: 92 ✭✭Silent Rain


    Shouldnt have to.
    The right outer join should work...
    Are you sure you arent accidently typing the name of the larger table twice in the join ?
    i.e. joining on itself ?


  • Closed Accounts Posts: 2,268 ✭✭✭mountainyman


    Thanks


    Tried that but it didn't work.

    Swapping the bit after the 'ON' didnt work

    (what's that called by the way?
    (Players p Right Outer JOIN Teams te ON p.team = te.PK)
    


  • Registered Users, Registered Users 2 Posts: 92 ✭✭Silent Rain


    SELECT *
    FROM Player
    SELECT *
    FROM Team
    SELECT *
    FROM Team T
    RIGHT OUTER JOIN Player P
    ON T.TeamID = P.TeamID


    PlayerID Name TeamID
    1 Dave 1
    2 John 3
    3 Mary 2
    4 Susan 5
    5 Sandra 4
    6 Nick 3
    7 Mick 2
    8 James 1
    9 John 1
    (9 row(s) affected)

    TeamID TeamName
    1 Tigers
    2 Panthers
    3 Seahawks
    (3 row(s) affected)

    TeamID TeamName PlayerID Name TeamID
    1 Tigers 1 Dave 1
    3 Seahawks 2 John 3
    2 Panthers 3 Mary 2
    4 Susan 5
    5 Sandra 4
    3 Seahawks 6 Nick 3
    2 Panthers 7 Mick 2
    1 Tigers 8 James 1
    1 Tigers 9 John 1
    (9 row(s) affected)

    Sorry about the poor formatting.... but is this not what you are going for ?


  • Moderators, Science, Health & Environment Moderators Posts: 10,093 Mod ✭✭✭✭marco_polo


    Looks like a full outer join (5*500)is being done by the query :confused:. What is the exact query you are using and ON which DB?


  • Advertisement
Advertisement
Advertisement