Rows in Columns

3

I have the following result of a query :

NOMECARACTERISTICA      NOMEINFORMACAO
Marca                   Samsung
Marca                   ASUS
Modelo                  E32 370E4K-KW3
Modelo                  X555LF

My idea is to transform it as follows:

Marca       Modelo
Samsung     E32 370E4K-KW3    
ASUS        X555LF

I created the query below:

SELECT 
    CASE WHEN NomeCaracteristica = 'Marca'  THEN NomeInformacao END AS Marca,
    CASE WHEN NomeCaracteristica = 'Modelo' THEN NomeInformacao END AS Modelo
FROM
(
    SELECT
       CAR.NomeCaracteristica AS NomeCaracteristica,
       INF.NomeInformacao AS NomeInformacao
    FROM
       caracteristica CAR INNER JOIN informacao INF ON CAR.IdCaracteristica = INF.IdCaracteristica 
    WHERE
       CAR.IdCategoria = 1 
    ORDER BY
       CAR.IdCaracteristica limit 4
) d

But it's bringing me the result:

MARCA       Modelo
Samsung     NULL    
ASUS        NULL
NULL        E32 370E4K-KW3 
NULL        X555LF

Can anyone help me get the result I need?

    
asked by anonymous 25.12.2016 / 16:08

1 answer

0

Sorry for the late feedback on this issue.

As previously stated by Bacco, it was missing a column in one of the tables to get this link.

That way, I was able to do the query I needed!

Thank you all!

    
17.01.2017 / 10:31