AI Workshop: learn to build apps with AI →
Prisma: Prisma, how to reverse order

Join the AI Workshop and learn to build real-world apps with AI. A hands-on, practical program to level up your skills.


I was getting data from the database using Prisma.

In my specific case I was getting tweets from the Tweets table, and they were listed from oldest to newest.

I wanted the opposite, like Twitter works - the newest shows up first.

So I looked at my data fetching procedure:

await prisma.tweet.findMany({})

and I added an orderBy attribute to order by id in descending order:

await prisma.tweet.findMany({
  orderBy: [
    {
      id: 'desc'
    }
  ]
})

Lessons in this unit:

0: Introduction
1: How to use Prisma
2: Prisma relations
3: Using multiple fields for a unique key in Prisma
4: ▶︎ Prisma, how to reverse order
5: Prisma, how to clear the database
6: How to solve the `prisma/client did not initialize yet` error on Vercel