About 15,600,000 results
Open links in new tab
  1. mysql - Can we sort a column lexicographically in SQL ... - Stack Overflow

    Sep 18, 2021 · If the values are the same, I want to sort the Name column lexicographically which means names - Apple and Carrom should shift one row up. SELECT Id, Name, Value from tbl; You can use this query. SELECT * FROM tbl ORDER BY Name, Value; You can select all Columns and order by Name and Value.

  2. MySQL ORDER BY Keyword - W3Schools

    The ORDER BY keyword is used to sort the result-set in ascending or descending order. The ORDER BY keyword sorts the records in ascending order by default. To sort the records in descending order, use the DESC keyword.

  3. MySQL :: MySQL 8.4 Reference Manual :: 5.3.4.4 Sorting Rows

    You can force a case-sensitive sort for a column by using BINARY like so: ORDER BY BINARY col_name. The default sort order is ascending, with smallest values first. To sort in reverse (descending) order, add the DESC keyword to the name of the column you are sorting by:

  4. How to master Natural Ordering in MySQL - my personal blog

    Apr 13, 2024 · There are several techniques to implement natural sorting in MySQL. Some of the most effective and practical methods are explored below. A simple way to approximate natural ordering is to use the length of the fields as a secondary criterion in the clause ORDER BY. This can be combined with a standard alphabetical sort:

  5. MySQL 'Order By' - sorting alphanumeric correctly

    Dec 19, 2011 · The type of sorting you are talking about is called "Natural Sorting". The data on which you want to do sort is alphanumeric. It would be better to create a new column for sorting. For further help check natural-sort-in-mysql

  6. mysql - Sorting field by numerical value and lexicographical value ...

    Aug 17, 2012 · Since the order numbers are stored as VARCHAR, they are sorted lexicographically. Problem is, not all order numbers are numerc, some are words, and others are alphanumeric. So, for example, I can have order numbers like so: When sorted using ORDER BY orderNumber, I get: DEMO: http://sqlfiddle.com/#!2/7973e/1. This is not what I want.

  7. SQL Order by lexicographical order, but with longer string first

    Apr 17, 2015 · In SQL Server, I have a table with a column I want to sort. If I apply the usual ORDER BY, it does the following, as expected: However, I would like to have them sorted this other way: Still lexicographically, but if the letters match and one is longer than the other, place the longer one first. Is it possible to do such a query in a T-SQL?

  8. How can I lexicographically sort numbers stored in a string?

    Nov 18, 2016 · First I use a declared table variable as a **mock-up* for a test scenario. The CTE will cut the numbers at the hyphen. Then use an numerical sort on both parts separately. ('1-1') SELECT LEFT(StringNumber,pos.Hyph-1) AS PartOne. ,SUBSTRING(StringNumber,pos.Hyph+1,1000) AS PartTwo. ,StringNumber. FROM @tbl AS tbl.

  9. mysql - How to sort on a column in Lexicographical order in php ...

    Oct 24, 2018 · let arr = [ '1 Hello', '2 Hello', '3 Hello', '4 Hello', ';1', 'z', '%1', '110 Hello', '100 Hello', 'a', 'Z', '00', '21 Hello', '9 Hello', '13 Hello', '10000 Hello', '0 Hello', 'A' ]; arr.sort( (a, b) => { return a.localeCompare(b, 'en', { numeric: true }) } ).forEach( ml => { console.log(ml) });

  10. Sort an Array of Strings in Lexicographical order

    Apr 19, 2025 · Given an array of strings arr [] of size n, the task is to sort all the strings in lexicographical order. Examples: Explanation: All strings are sorted alphabetically. “apple” comes before “banana”, and “banana” before “cherry”. Explanation: “bat” is the smallest, followed by “cat”, and then “dog” in lexicographical order.

  11. Some results have been removed
Refresh