How to return values from different columns without repeating? [closed]

0

I'm trying to capture and print all the categories in a table, but I do not want them to repeat themselves. Notice that there are 4 columns of different categories below:

NUMEROID-----NOME-----CATEGORIA1-----CATEGORIA2-----CATEGORIA3-----CATEGORIA4
00001      wordart      Jogos         Saude          Saude         Culinaria
00002      wonderl      Noticias      Noticias       Jogos         Arte
00003      heaveng      Arte          Jogos          Jogos         Jogos
00004      flowwav      Arte          Saude          Jogos         Saude

I would like to print (in php) on the screen a list like in the example below: (If possible in alphabetical order)

  • Art
  • Cooking
  • Games
  • News
  • Health

Thank you all.

    
asked by anonymous 01.02.2017 / 03:25

1 answer

1

A way to solve only in the query:

     SELECT CATEGORIA1 AS CATEGORIA FROM NOME_DA_TABLE
     UNION
     SELECT CATEGORIA2 AS CATEGORIA FROM NOME_DA_TABLE
     UNION
     SELECT CATEGORIA3 AS CATEGORIA FROM NOME_DA_TABLE
     UNION
     SELECT CATEGORIA4 AS CATEGORIA FROM NOME_DA_TABLE

O Union irá fazer o trabalho!

link

    
01.02.2017 / 03:48