📆 Don't miss our Sanity Showcase virtual meetup on March 20th!

Use GROQ to order by last name in where name is stored as full name

By Sigurd Heggemsnes

Order by last name

Model

{
  type:"document",
  name:"person",
  fields: [
    {
      name:"name",
      type:"string
    }
  ]
}

Query

*[_type == "person"]|order(string::split(name, " ")[-1], asc)[0...12]

This example is based on having a "person" document type

Contributor

Other schemas by author