Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Simple SQL Question on Joins

  • 06-11-2008 4: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,088 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