Side-by-side comparison of data by year in SQL
I have table similar to the following: Year | Product | Value 2006 A 10 2006 B 20 2006 C 30 2007 A 40 2007 B 50 2007 C 60 I would like a query that would return the following comparison Product | 2006 Value | 2007 Value A 10 40 B 20 50 C 30 60 What are the options to do so? Can it be done without joins? I'm working with DB2, but answers in all SQL types would be helpful. select Product, max(case when Year = 2006 then Value end) as [2006 Value], max(case when Year = 2007 then Value end) as [2007 Value] from MyTable group by Product order by Product A simple cross tab query should do it SELECT