I need to join two tables called MSISDN and RANGES.
Example:
MSISDN table:
MSISDN NETWORK
110011500 D000
110211501 D000
RANGES table:
PREFIX NETWORK DESCRIPTION
11 D000 NEOTEL
1102 D000 TELKOM
I’m joining as:
select *
from MSISDN a
left join RANGES b
on a.msisdn like b. prefix || '%'
and a.network = b.network;
This query will give me duplicates in case as for MSISDN ‘110211501’, because it will match with both prefixes.
I need to avoid these duplicates. I need to only have the match with the longest prefix (in this case ‘1102’).
Is there any way how to join avoiding the duplicates or doing de duplication afterwards?
Try the following query:
it should remove the duplicates and give you the records with longer prefix.