🔮 Sanity Create is here. Writing is reinvented. Try now, no developer setup

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