Skip to content
Advertisement

SQL join to find relavant codes and address

Below table contain address information.

Code Code1 Code2 Address
DAN001 DAN004 DAN005 ABC, Newyork.
DAN004 DAN004 DAN004 Delhi, India
DAN005 DAN005 DAN005 Ever, Belgium

Please find table details below:

Each Code have associated code1 and code2 and address last column. for example:

  • DAN001 is associated with DAN004 and DAN005.
  • Address for DAN001 is ABC, Newyork.
  • Address for DAN004 is Delhi,India.
  • Address for DAN005 is Ever, Belgium.

I am looking for the single SQL query, which will give me associated code1 and code2 and corresponding addresses for each codes in the single query for the given code.

I made below query but this is not working as excepted:

I am using Oracle10g.

Excepted result:

DAN004, ABC Newyork, DAN005, EVER Belgium

Advertisement

Answer

Are you just looking for joins?

This uses left join in case any of the code columns are empty.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement