Question

I have a mysql database that looks like this:

proj_id | job1_name | job1_type | job1_time | job2_name | job2_type | job2_time | ...
--------+-----------+-----------+-----------+-----------+-----------+-----------| ...
      1 | John      | Roof      |        10 | Jane      | Floor     |         2 | ...

Actual table has these three fields (name, type, and time) for up to 5 jobs.

I need the results to display in a table like this:

proj_id |  Name  |   Type   | Time
--------+--------+----------+------
      1 | John   | Roof     |   10
      1 | Jane   | Floor    |    2

How can I accomplish this?

thanks for all the help!!

Jay

Was it helpful?

Solution

Using Union, you can get the results as you want. But I'm not sure whether it is a good solution.

SELECT `proj_id`,`job1_name` AS 'Name',`job1_type` AS 'Type',`job1_time` AS 'Time'
FROM `job`
WHERE 1
UNION
SELECT `proj_id`,`job2_name` AS 'Name',`job2_type` AS 'Type',`job2_time` AS 'Time'
FROM `job`
WHERE 1

Why you are having 5 jobs data in different fields. You can add job_id for the reference and other fields as common.

Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top