Left Join

  • Example

    table employee has 1319 rows

    do a left join and get 1798 rows

    I thought it automatically brings in according to the

    from table and if it doesnt have a value leaves it null.

    select a.*, b.number

    from employee a

    left join b on a.project = b.project

    these are temp tables, is that an issue?

    Why am I getting more rows, and have to modify with a where clause to bring the number down, but then its 1295 rows.

  • If b has multiple rows with the SAME value in project, then it's going to "duplicate" or rather show duplicatively the same row from employee.

    you could try throwing a DISTINCT in there and see if the count is closer to what you wish.

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • Thanks Matt, specifically it reduced 19 rows which was an error on the previous stored procedure as well. And for reference for anyone who finds this thread there can be more then one on clause

    meaning:

    from b

    left join on a

    a.column = b.column

    and

    a.column1 = b.column1

    and

    a.column2 = b.column2

    order by column----remember this or it will look like junk

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply