Home Page for the TeradataForum

Archives of the TeradataForum

Message Posted: Tue, 04 Jan 2011 @ 07:36:16 GMT

  <Prev Next>   <<First <Prev

Subj:   Re: Need help on LEFT JOIN - count more than left
From:   Minakshi Swami


This is simply because your id (the joining column) in first table have more than one recs in second table.

For eg.

First table has below values

     emp_id   name
     1        a

Second table have below values

     emp_id   name
     1        b
     1        c
     1        ?
     1        b

Now the result of below query will 4, because for each matching value it will count the corresponding row in second table

     sel count(*) from
     first a
     left join
     second b
     on a.emp_id=b.emp_id

Incase you join on emp_id and name both then the count(*) will give 1(values for corresponding row of second table will null).If you give where (b.emp_id is not null and b.name is not null) then left join will work as inner join.



  <Prev Next>   <<First <Prev
  Top Home Privacy Feedback  
Copyright for the TeradataForum (TDATA-L), Manta BlueSky    
Copyright 2016 - All Rights Reserved    
Last Modified: 15 Jun 2023