Subject More than one column in "IN" clause
Author RCN Listas
Hi there!!



First of all I would like to thank all of you for receiving me here.



I'm facing a big doubt for me, because I'm not expert in database or little
complex queries, but simple selects and DMLs, as a developer.



The situation is the following:



1) I have 3 tables, as follows (table and columns):

Table1

Cod1

Name1



Table2

Cod1 (from Table1)

Cod2

Name2



Table3

Cod1 (from Table2)

Cod2 (from Table2)

Cod3

Name3



2) I'd like to select all records from Table3 where the related Name1 start
with "ABC", then I wrote the following:

select * from Table3 where Table3.Cod2 in (select Table2.Cod2 from Table2
where upper(Table2.Name2) like 'ABC%')



3) As, in Table2, I reset Cod2 for each new increment of Cod1, I have my
problem: supposing when I run the previous select I receive a value 1 as
Cod2 from Table2 (nested query) than, in Table3 I will have all records
where Cod2 is equal to 1, independent of Cod1, which is very important.



I thought that if I could use de Table3.Cod1 and Table3.Cod2 in the "IN"
statement, I could solve the problems, so I would be matching both 2
segments from my primary key, but I don't know how to do this or similar
solution.



So, I would very glad if anyone can help me.



Thank you very much,



Best regards,



Rafael



[Non-text portions of this message have been removed]