Skip to content
Advertisement

How to join tables on calculation – Oracle [closed]

i am trying to join these two tables, but I can only do so if I change values of columns while joining like “substr(to_char(p.personnummer),3)” and “substr(k.ip_id,1,10)” . Can anyone tell me what is the order I am supposed to do it?

select x.ip_id, x.organisationsnummer 
from (select 
    substr(to_char(p.personnummer),3) as ip_id_jnr, 
    substr(k.ip_id,1,10) as ipo_id
    from customer k
inner join customer_VIEW p on ipo_id = ip_id_jnr) x
;

Advertisement

Answer

Your query doesn’t show which table contains organisationsnummer; I used the k alias (as if it belongs to customer); fix it if necessary.

So, inline view:

select k.organisationsnummer,
       k.ip_id
from customer k join customer_view p 
  on substr(to_char(p.personnummer),3) = substr(k.ip_id,1,10);

Now use it:

select x.ip_id, 
       x.organisationsnummer
from (select k.organisationsnummer,
             k.ip_id
      from customer k join customer_view p 
        on substr(to_char(p.personnummer),3) = substr(k.ip_id,1,10)
     ) x;
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement