({{, (RefLink[SortedEntityClass, paclet:ref/SortedEntityClass])[class,prop] 
represents an entity class derived from class by sorting according to the values of the property prop. }, {, (RefLink[SortedEntityClass, paclet:ref/SortedEntityClass])[class,prop->"order"]
sorts according to prop in the order specified.}, {, (RefLink[SortedEntityClass, paclet:ref/SortedEntityClass])[class,{(Subscript[prop, 1]),(Subscript[prop, 2]),…}]
breaks ties by successively using the values of the property specifications (Subscript[prop, i]).}, {, (RefLink[SortedEntityClass, paclet:ref/SortedEntityClass])[class,sortspec,n]
represents the first n entities of class when sorted by sortspec.}, {, (RefLink[SortedEntityClass, paclet:ref/SortedEntityClass])[class,sortspec,{m,n}]
represents the entities m through n of class when sorted by sortspec.}})

OpenersNotesSection(Spacer1)Details

In (RefLink[SortedEntityClass, paclet:ref/SortedEntityClass])[class,sortspec,n], when class contains fewer than n entities, all entities are used.

In (RefLink[SortedEntityClass, paclet:ref/SortedEntityClass])[class,{(Subscript[prop, 1]),(Subscript[prop, 2]),…}], (Subscript[prop, i]) can be given as (RefLink[EntityProperty, paclet:ref/EntityProperty]), (RefLink[EntityFunction, paclet:ref/EntityFunction]) or string.

(RefLink[SortedEntityClass, paclet:ref/SortedEntityClass])[class,prop,-n] is effectively equivalent to (RefLink[SortedEntityClass, paclet:ref/SortedEntityClass])[class,prop->"Descending",n].

OpenersPrimaryExamplesSection(Spacer1)Examples  (8)

OpenersExampleSection0(Spacer1)Basic Examples  (5)

Use (RefLink[SortedEntityClass, paclet:ref/SortedEntityClass]) to sort a class of entities:

EntityList[SortedEntityClass["Country", "Population"]]

Change the direction of the order:

EntityList[SortedEntityClass["Country", "Population" -> "Descending"]]

Take only the first 10 entities:

EntityList[SortedEntityClass["Country", "Population" -> "Descending",10]]

Sort by multiple criteria:

EntityList[SortedEntityClass["Element", {"Group","Period"}]]

When used with relational-database-backed entities, (RefLink[SortedEntityClass, paclet:ref/SortedEntityClass]) is equivalent to an ORDER BY statement:

EntityRegister[EntityStore[RelationalDatabase[FindFile["ExampleData/ecommerce-database.sqlite"]]]]

SortedEntityClass["payments" , "amount",10]["amount"]

OpenersExampleSection1(Spacer1)Scope  (1)

The second argument of (RefLink[SortedEntityClass, paclet:ref/SortedEntityClass]) can be an (RefLink[EntityFunction, paclet:ref/EntityFunction]):

EntityList[SortedEntityClass[(EntityClass["Europe", EntityClass["Country","Europe"], "EntityClass[\"Country\", \"Europe\"]", "countries"]), EntityFunction[c, c[]/c[(EntityProperty["population", EntityProperty["Country","Population"], "EntityProperty[\"Country\", \"Population\"]"])]-> "Descending"],3]]

OpenersExampleSection3(Spacer1)Properties & Relations  (1)

When (RefLink[SampledEntityClass, paclet:ref/SampledEntityClass]) is applied to (RefLink[SortedEntityClass, paclet:ref/SortedEntityClass]):

EntityList[SampledEntityClass[SortedEntityClass["Dinosaur",(EntityProperty["full length", EntityProperty["Dinosaur","Length"], "EntityProperty[\"Dinosaur\", \"Length\"]"])-> "Descending"] , 2]]

The same class can be more simply expressed by using (RefLink[SortedEntityClass, paclet:ref/SortedEntityClass]) with three arguments:

EntityList[SortedEntityClass["Dinosaur",(EntityProperty["full length", EntityProperty["Dinosaur","Length"], "EntityProperty[\"Dinosaur\", \"Length\"]"])-> "Descending", 2]]

OpenersExampleSection4(Spacer1)Neat Examples  (1)

Make a map of the 10 largest countries by population:

GeoListPlot[EntityList[SortedEntityClass["Country", "Population"->"Descending", 10]]]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[EntityValue, paclet:ref/EntityValue])  ▪  (RefLink[EntityList, paclet:ref/EntityList])  ▪  (RefLink[EntityStore, paclet:ref/EntityStore])  ▪  (RefLink[EntityFunction, paclet:ref/EntityFunction])  ▪  (RefLink[Sort, paclet:ref/Sort])  ▪  (RefLink[SortBy, paclet:ref/SortBy])  ▪  (RefLink[ReverseSort, paclet:ref/ReverseSort])  ▪  (RefLink[SampledEntityClass, paclet:ref/SampledEntityClass])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Working with Information in Relational Databases, paclet:guide/WorkingWithRelationalDatabases])}, {▪(RefLinkPlain[Knowledge Representation & Access, paclet:guide/KnowledgeRepresentationAndAccess])}, {▪(RefLinkPlain[Database Connectivity, paclet:guide/DatabaseConnectivity])}})}})