1

This is my H2 table.

| Step 1 | time |
| Step 2 | time |
| Step 3 | time |
| Step 4 | time |
| Step 5 | time |
| Step 1 | time |
| Step 2 | time |
| Step 3 | time |
| Step 4 | time |
| Step 5 | time |

I need to write a SQL query that fetches the result like so:

| Step 1 | time | time |
| Step 2 | time | time |
| Step 3 | time | time |
| Step 4 | time | time |
| Step 5 | time | time |

How do I fetch it this way? Is this possible?

dkulkarni
  • 2,780
  • 4
  • 27
  • 36
  • Do you have only two values for each step or can you have more? – Marco Nov 21 '11 at 07:22
  • These are test results. So if there are ten steps and the test was executed 5 times, then I would have Step 1 through 10 five times along with the time taken for each of those steps – dkulkarni Nov 21 '11 at 07:23
  • This is a specific instance of [this question](http://stackoverflow.com/questions/102317/how-to-get-multiple-records-against-one-record-based-on-relation/106334) – mdahlman Nov 21 '11 at 07:33

1 Answers1

2

If you have more than two values for each step, you could do

SELECT step_col, GROUP_CONCAT(time_col)
FROM H2 GROUP BY step_col

Then you can easily split time_col values in your code.
Check GROUP_CONCAT syntax to understand how you can use it the way you please.

Marco
  • 56,740
  • 14
  • 129
  • 152