SQL - Changing Field Names within a Column

0

Well, I have a question, I have for example a column called "Categories" and within that column I have several fields (categories) and wanted to change the names of those fields.

For example "column categories" - and within it I have several categories with the following names: RMS-FOOTBALL; RMS-BASQUET; RMS-TENNIS; RMS-BADMITON; (...); and wanted to change those names within that column for: Football; Basquet; Sneakers; Badminton, and so on.

Can anyone help me? I have an idea that by update maybe it is possible to do but I am not seeing how to change several field names within the same column agregdecia a help with this example that I gave thanks.L

    
asked by anonymous 06.07.2018 / 01:18

1 answer

1

You can run these UPDATE s:

UPDATE sua_tabela SET categorias = 'Futebol' WHERE categorias = 'RMS-FUTEBOL';
UPDATE sua_tabela SET categorias = 'Basquet' WHERE categorias = 'RMS-BASQUET';
UPDATE sua_tabela SET categorias = 'Tenis' WHERE categorias = 'RMS-TENIS';
UPDATE sua_tabela SET categorias = 'Badminton' WHERE categorias = 'RMS-BADMITON';

To check if something is still missing:

SELECT DISTINCT categorias FROM sua_tabela WHERE categorias LIKE 'RMS-%';

Or, to see all the categories and check if there are none wrong:

SELECT DISTINCT categorias FROM sua_tabela;

In all these cases sua_tabela is the name of the table that has the categorias column.

    
06.07.2018 / 01:32