<p>I'm working on trying to generate a report from a couple of database tables. The simplified version looks like this</p>

<pre><code>Campaign
----------
CampaignID

Source
-----------------------
Source_ID | Campaign_ID

Content
---------------------------------------------------------
Content_ID | Campaign_ID | Content_Row_ID | Content_Value
</code></pre>

<p>The report needs to read like this:</p>

<pre><code>CampaignID - SourceID - ContentRowID(Value(A)) - ContentRowID(Value(B))
</code></pre>

<p>Where ContentRowID(Value(A)) means "Find a row the has a given CampaignID, and a ContentRowId of "A" and then get the ContentValue for that row"</p>

<p>Essentially, I have to "pivot" (I think that's the correct term) the rows into columns...</p>

<p>It's an Oracle 10g database...</p>

<p>Any suggestions?</p>

This is my first stab at it. Refinement coming once I know more about the contents of the Content table.
First, you need a temporary table:
```
```
CREATE TABLE pivot (count integer);
INSERT INTO pivot VALUES (1);
INSERT INTO pivot VALUES (2);
```
```
Now we're ready to query.
```
```
SELECT campaignid, sourceid, a.contentvalue, b.contentvalue
FROM content a, content b, pivot, source
WHERE source.campaignid = content.campaignid
AND pivot = 1 AND a.contentrowid = 'A'
AND pivot = 2 AND b.contentrowid = 'B'
```
```