Home > Enterprise >  Order by multiple fields in list of entity
Order by multiple fields in list of entity

Time:10-05

I have a list of survey answers. Each answer store in table as value with id reference to parent survey field and reference to person who answer. Parent field store title and type of question. Can i with sql do sort by multiple fields?

The problem for me is that answer value for multiple fields store in one table in one column as text.

CodePudding user response:

If the fields are all concatenated into one column, you may need to separate them all into individual columns using a string function like substring or charindex, but it depends how much detail you need to retrieve and what separator is in the column that you can work with.

You might be able to get away with using ORDER BY LEFT(yourColumn, countOfCharUpToEndUniqueID) but only if the values are in the right order.

CodePudding user response:

The SQL syntax is:

SELECT column1, column2, ...
FROM table_name
ORDER BY column1, column2, ... ASC|DESC;

That means that also can define ASC or DESC by column.

  • Related