Sorting by multiple fields at same time in QGIS?

You can use the Sort and Number plugin. It allows you to sort an attribute table by up to 3 fields, then it creates an additional field that contains the order of the sorted features.

Disclaimer: I'm the author of the plugin.


If is OK to save the result permanently you can sort the shapefile with GDAL

ogr2ogr -f "ESRI Shapefile" -dialect sqlite -sql "SELECT *
FROM my_shapefile ORDER BY attr_1, attr_2, attr_3" sorted.shp my_shapefile.shp

Took less that 3 minutes with a shapefile having one million polygons.


The DB Manager plugin in QGIS now has a 'Virtual Layers' node that allows you to write SQL commands against shapefiles loaded into your QGIS project.

So now that you have this ability, the SQL logic to sort by multiple fields is in the ORDER BY statement, using asc (ascending), desc (Descending), and you can string them together to sort by multiple columns:

enter image description here

An added bonus is you'll learn more SQL so when you get sick of shapefiles and most to PostGIS the leap won't be so great!!!