SQL Alphabetical sorting with html code

Asked

Viewed 97 times

1

I have a table that contains the field titulo. I have a query and want to sort alphabetically by it, however, some fields are with HTML code, I will give examples:

Goat Slaughter and Meat Processing

Slaughter and Marketingçãthe Animal

In the second example, for the user the correct name appears Abate e Comercialização de Animais, but in the database is in the form shown above.

It is possible to sort alphabetically considering the text without the html codes, as text "readable"?

1 answer

1


You can work around the problem by creating another column in your database where you store the titles accentuated.

So, when ordering, you can use this new column (titulo_com_acentos). When returning the information to the screen, you can use the current column.

 id | titulo                                           | titulo_com_acentos
 1  | Abate e Comercialização de Animais | Abate e Comercialização de Animais

This type of solution is quite common when we need to extract certain information from a column in the table but, for some reason, it is impossible to extract this information at runtime. Then this information extraction is done in a previous step and saved in the database, synchronized with the original information.

  • 1

    It turns out I’m gonna have to do something like that. Instead of getting around the problem, in the programming, where you insert it into the database, I will insert it without the html code every time and run a routine in sql to replace these codes. Then I keep a field only. But thank you, your solution solves the problem.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.