Table 1:
id | typeid | available|
0 | 1 | 12 |
0 | 2 | 44 |
Table 2:
<
You should use table pivoting. There is no PIVOT command in MySQL, so you can use this query -
SELECT
t1.id,
MAX(IF(t2.typename = 'CL', t1.available, NULL)) AS CL,
MAX(IF(t2.typename = 'ML', t1.available, NULL)) AS ML
FROM table1 t1
JOIN table2 t2
ON t1.typeid = t2.typeid
GROUP BY
t1.id;
MySQL pivot tables (transform rows to columns).
Use GROUP_CONCAT function instead of MAX, if multiple available values are possible.