SELECT * FROM action_has_providers
action_ID prov_title track_no
10001 ProvA #12345
10001 ProvB AB123
10001 ProvC R-0001
10002 ProvB AC456
10002 ProvC R-0002
10003 ProvA #98765
action_ID prov_title track_no prov_title track_no prov_title track_no
10001 ProvA #12345 ProvB AB123 ProvC R-0001
10002 ProvB AC456 ProvC R-0002
10003 ProvA #98765
SELECT `t`.`action_ID`, `t1`.`prov_title` AS `prov_title_A`, `t1`.`track_no` AS `track_no_A`,
`t2`.`prov_title` AS `prov_title_B`, `t2`.`track_no` AS `track_no_B`,
`t3`.`prov_title` AS `prov_title_C`, `t3`.`track_no` AS `track_no_C`
FROM (
SELECT DISTINCT `action_ID`
FROM `action_has_providers`
) AS `t`
LEFT JOIN `action_has_providers` AS `t1`
ON `t1`.`action_ID` = `t`.`action_ID` AND `t1`.`prov_title` = 'ProvA'
LEFT JOIN `action_has_providers` AS `t2`
ON `t2`.`action_ID` = `t`.`action_ID` AND `t2`.`prov_title` = 'ProvB'
LEFT JOIN `action_has_providers` AS `t3`
ON `t3`.`action_ID` = `t`.`action_ID` AND `t3`.`prov_title` = 'ProvC'
CREATE TABLE "T" (
`action_ID` INTEGER NOT NULL,
`prov_title` TEXT NOT NULL,
`track_no` TEXT NOT NULL
);
INSERT INTO `T` VALUES
(10001,'ProvA','#12345'),
(10001,'ProvB','AB123'),
(10001,'ProvC','R-0001'),
(10002,'ProvA','AC456'),
(10002,'ProvB','R-0002'),
(10002,'ProvC','#98765');
SELECT
A.action_ID,
A.track_no,
B.track_no,
C.track_no
FROM (SELECT * FROM T WHERE prov_title = "ProvA") AS A
JOIN (SELECT * FROM T WHERE prov_title = "ProvB") AS B
JOIN (SELECT * FROM T WHERE prov_title = "ProvC") AS C
ON A.action_ID = B.action_ID AND A.action_ID = C.action_ID;