Skip to content
Advertisement

Oracle join query

There are three tables in my db: ITEM_MASTER, PRICE_MASTER and COMP_MASTER.

I want to get all these for an ITEM_CODE in a single query.

How can I write an oracle SQL query for this?

Advertisement

Answer

There are two steps involved to get this output: a join and a pivot.

An example:

First create your sample tables:

First step is the join. Here I use ANSI join syntax, but you can use good old Oracle join syntax as well.

The comp description appear below each other, but you want them to be next to each other. To achieve that, you pivot the result set. Note that you have to hard code the number of rows you want to pivot:

Hope this helps.

Regards, Rob.

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