Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query puzzle: Same table query comparison of two fields

Status
Not open for further replies.

shyamal

Programmer
Aug 14, 2000
79
US
I have the following fields in the security table:
I would like to return all sc_adp_nums where sc_underly_adp_num has a matching sc_symbol. In this example, I would like 000361105 returned as the sc_symbol matches with the sc_underly_adp_num that 000361GFC has.

sc_adp_num sc_symbol sc_underly_adp_num
------------- ------------ ------------------
000360206 AAON
000361105 AIR
000361GFC AIRGF AIR
000369348 FLXT
12486QLHC .648815108 .648815108
18799WPLP AOOPL AOOPL

I ran the following query:
select sc_adp_num, sc_symbol from security
where sc_underly_adp_num = sc_symbol which resulted in this:
This is not correct because it is an exact match:-

sc_adp_num sc_symbol sc_underly_adp_num
------------- ------------ ------------------
12486QLHC .648815108 .648815108
18799WPLP AOOPL AOOPL

Thanks in Advance.
S.Leonard
 
You would need to join the table to itself...

Try...

select a.sc_adp_num, b.sc_symbol
from security a, security b
where a.sc_underly_adp_num = b.sc_symbol
and a.sc_adp_num != b.sc_adp_num
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top