I'm trying to mount a select that has the result below:
With the select below I can see null in only one column. How could I make it work for 20? I have item_1 through item_20 and the item description is in the parts table, in the occurrences it has only its code.
SELECT P1.descricao desc1
FROM ocorrencias
LEFT JOIN pecas P1
ON P1.cod_peccin=ocorrencias.item_1
WHERE ocorrencias.cod = 2
I tried this way with two columns, but it did not work:
SELECT P1.descricao desc1, P2.descricao desc2
FROM ocorrencias
LEFT JOIN pecas P1, pecas P2
ON P1.cod_peccin=ocorrencias.item_1, P2.cod_peccin=ocorrencias.item_2
WHERE ocorrencias.cod = 2