Question : SQL Help needed... UNIQUE()

I'm trying to get a list of Unique items from a query result. I've attached three files as examples of the data results from my current query and my expected unique list.

I'm trying to get a result similar to file unique_list_C.txt subaccounts (111,222,333, etc.).

In my current query results table_export_A.txt or table_export_B.txt the item 6662201 is at LEVEL 11 and LEVEL 12 respectively but could be at any LEVEL() and the subaccount (111,222,333, etc.) LEVEL 12 and LEVEL 13  respectively will always follow the item column.

I hope I've explained this correctly, please let me know if there are any questions and I will try again...

Thanks for any help.

NG,

Attachments:
 
table_export_a
 
 
table_export_b
 
 
unique_list_c
 

Answer : SQL Help needed... UNIQUE()

Some questions:
So your items are at
level1, level3 , level4 ,  ...
and
your
subaccounts on
level2,level4,level6, ...   ???
If so what is the maximum level

And you are searching for all subaccounts or are you searching for all-subaccounts of an item ?
If the last is true are you searching for a particular item, or do you want all items listed with there unique
subaccount.

To give it a try: if the item. subaccount paires start at level 5 and end at level 10
Finding all unique paires :

select distinct item, subaccount
from
(
select level5 item, level6 subaccount from tablex
union
select level7, level8 from tablex
union
select level9, level10 from tablex
)
order by item,subaccount
/
 
Random Solutions  
 
programming4us programming4us