SQL Query Help

  • I have two tables.

    Table 1 has field1, field2 , field 3

    Table 2 has field1, field2, field4

    Can somnebody tell me a query where i can compare these two tables on field1 & field2 together and if they together have same values then give me the result set

    eg:

    field1 field2 field3 field1 field2 field4

    1 1 2 1 1 4

    1 2 2 1 3 2

    Then i want only

    field1 field2 field3

    1 1 2

    Please help.

    thanks

    Hari

  • Try:

    SELECT A.Field1, A.Field2, A.Field3

             FROM Table1 A

                    INNER JOIN Table 2 B

                             ON B.Field1 = A.Field1

                             AND B.Field2 = A.Field2

    If Field1/Field2 do not constitue the full key on Table2 then it is possible for the above to replicate some of the Table1 results. If that is the case it sounds like you could get rid of them simply by using DISTINCT.

     

  • Hi,

    Not really sure waht you want but I'll guess anyway.

    Select   T1.field1,

               T1.field2,

               T1,field2,

               T2.field1, -- probably don't need

              T2.field2, -- these bits

              T2,field4

    from   table1 T1

    join    table2 T2

    on     T1.field1 = T2.field1

    and    T1.field2 = T2.field2

    If this doesn't do what you want can you post a bit more info to clarify the request.

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

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