This query with left join
syntax, relates two tables, the table tbl_t
and the table tbl_p
SELECT
tProgr,
tLevel,
pProg_related,
pLevel
FROM
tbl_t t
LEFT JOIN tbl_p p ON t.tProgr = p.tProgr
WHERE
t.tProgr = '2022-0071'
ORDER BY
t.tProgr DESC;
The return
-------------------------------------------------------
| tProgr | tLevel | pProg_related | pLevel |
-------------------------------------------------------
| 2022-0071 | Principal | 2022-0010 | Secondary |
| 2022-0071 | Principal | 2022-0065 | Secondary |
| 2022-0071 | Principal | 2022-0076 | Secondary |
| 2022-0071 | Principal | 2022-0182 | Secondary |
| 2022-0071 | Principal | 2022-0223 | Secondary |
-------------------------------------------------------
How do I get this return instead?
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| tProgr | tLevel | pProg_related | pLevel | pProg_related | pLevel | pProg_related | pLevel | pProg_related | pLevel | pProg_related | pLevel |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| 2022-0071 | Principal | 2022-0010 | Secondary | 2022-0065 | Secondary | 2022-0076 | Secondary | 2022-0182 | Secondary | 2022-0223 | Secondary |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Any help really appreciated.
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| tProgr | tLevel | pProg_related | pLevel | pProg_related | pLevel | pProg_related | pLevel | pProg_related | pLevel | pProg_related | pLevel |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| 2022-0071 | Principal | 2022-0010 | Secondary | 2022-0065 | Secondary | 2022-0076 | Secondary | 2022-0182 | Secondary | 2022-0223 | Secondary |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------