Skip to content
Fix Code Error

SQL multiple column ordering

March 13, 2021 by Code Error
Posted By: Anonymous

I am trying to sort by multiple columns in SQL, and in different directions. column1 would be sorted descending, and column2 ascending.

How can I do this?

Solution

ORDER BY column1 DESC, column2

This sorts everything by column1 (descending) first, and then by column2 (ascending, which is the default) whenever the column1 fields for two or more rows are equal.

Answered By: Anonymous

Related Articles

  • CSS Float: Floating an image to the left of the text
  • SQL query return data from multiple tables
  • "Large data" workflows using pandas
  • Sort table rows In Bootstrap
  • SQLiteDatabase.query method
  • Sorting Backbone Collections
  • Why is there no SortedList in Java?
  • Getting a "TypeError" when trying to validate a form
  • Update rows in one table with data from another…
  • How to edit `cell[i]` in data grid view C# win form…
  • Unset WooCommerce checkout fields based on cart…
  • Add column to SQL query results
  • Remove similar tuple from dictionary of tuples
  • How to select the comparison of two columns as one…
  • data.table vs dplyr: can one do something well the…
  • How to reset a vue-infinite-loading element?
  • Difference between natural join and inner join
  • How to concatenate cell values until it finds a…
  • How to make Lodash sortBy() to sort data to…
  • Pandas comparing two rows in a database
  • What algorithms compute directions from point A to…
  • How to sort an array in Bash
  • How to apply ascending sort to split data in datatable
  • Add unique constraint to combination of two columns
  • How to sort a dataFrame in python pandas by two or…
  • sorting and paging with gridview asp.net
  • 3 column layout HTML/CSS
  • C++ Need help sorting a 2D string array
  • How can I pass a wct test while rearranging children…
  • Javascript dynamic sorting array of object include…
  • TypeScript metadata reflection references other…
  • How to sort an array in descending order in Ruby
  • How can I pass modelformset_factory validation in Django?
  • CSS Variable trough Polymer (dynamically loaded) elements
  • MySQL combine two columns into one column
  • python 3.2 UnicodeEncodeError: 'charmap' codec can't…
  • Centering in CSS Grid
  • Change column type in pandas
  • How to pass 2D array (matrix) in a function in C?
  • What is a "cache-friendly" code?
  • How do SO_REUSEADDR and SO_REUSEPORT differ?
  • Perfomance issues with large number of elements in…
  • Select * from subquery
  • Sorting an ArrayList of objects using a custom sorting order
  • Why is processing a sorted array faster than…
  • CASE WHEN statement for ORDER BY clause
  • Selecting range by finding start/end row number…
  • Setting equal heights for div's with jQuery
  • What is stability in sorting algorithms and why is…
  • Vuejs - cannot ready property of undefined - (but it…
  • How are iloc and loc different?
  • Combine two tables that have no common fields
  • Self-referencing topological execution order in svelte
  • Sorting backbone collections with multiple attributes
  • Ember: What is the non controller way to sort an…
  • Handling NULL values in Hive
  • How to prevent scrolling the whole page?
  • Problems with the size of the labels of the plots in R
  • The second execution of jquery datatable dont redraw…
  • Spark DataFrame groupBy and sort in the descending…
  • Memcached vs. Redis?
  • How to DROP multiple columns with a single ALTER…
  • Select rows with unique values for one specific…
  • Sort a list of numerical strings in ascending order
  • JavaScript gives NaN error on the page but variable…
  • How to solve Internal Server Error in Next.Js?
  • Ember sortBy on property:desc is not the same as reverse
  • What does the Excel range.Rows property really do?
  • Sortable row groups (+ group child rows) with Aurelia
  • Array.Sort doesn't work correctly in for{} loop
  • GridView sorting: SortDirection always Ascending
  • How do I sort a dictionary by value?
  • Advice on Perl sort that uses Schwartzian transform
  • Excel VBA - Separate data by pattern by using Split Function
  • How can building a heap be O(n) time complexity?
  • Fastest way to pad a dataframe with uneven columns
  • Using a value convertor on an ES 6 Map in Aurelia
  • Local Storage to store ascending/descending order
  • Individual click handlers in v-for loop
  • How does database indexing work?
  • In CSS Flexbox, why are there no "justify-items" and…
  • How to update google-maps-react direction route?
  • Java Array Sort descending?
  • Pandas - Reshape a dataframe columns based on…
  • how to print greatest sum each rows in python?
  • Heroku "Missing required flag -a --app" error after…
  • Ember data FixtureAdapter hasmany - Cannot call…
  • Table sorted date not correct
  • How do I limit the number of rows returned by an…
  • How to sort by column in descending order in Spark SQL?
  • Polymer 1.0 'array-style' path accessors,…
  • Sorting a HTML table with Array#sort
  • ascending/descending in LINQ - can one change the…
  • How to find Control in TemplateField of GridView?
  • How to sort encrypted column data?
  • Hide/Show Column in an HTML Table
  • Check if input field is changed
  • Sorting A Table With Tabs & Javascript
  • Sorting using Comparator- Descending order (User…
  • How to Display Multiple Google Maps per page with API V3

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

How do I ignore an error on ‘git pull’ about my local changes would be overwritten by merge?

Next Post:

Remove ALL white spaces from text

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error