Simple join gives unnecessary rows,How to get join properly with only matches in both tables

Posted by LS on Stack Overflow See other posts from Stack Overflow or by LS
Published on 2010-03-11T18:03:52Z Indexed on 2010/03/11 18:09 UTC
Read the original article Hit count: 518

Filed under:
|
Table 1
Field1 Field2  
AA 20
AA 20
AB 12
AC 13

Table2
field3 field4
AA 20
AA 20
AC 13
AD 23
AW 21

output required:

newfield field2 field4
AA   20 20
AA   20 20
AC   13 13

I used:

 select field1 as newfield, t1.field2,t2.field4
      from table1 t1 join table2 t2 on t1.field1=t2.field3

This does not give the required output,Please let me know how to get the required output,Many thx in advance

© Stack Overflow or respective owner

Related posts about sql

Related posts about join