👋 Next.js Conf 2024: Come build, party, run, and connect with us! See all events

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