What is the best way to get distinct values from a table?

I am curious what would be the best way to get distinct values from a table. I have

export async function getYearsThatHaveVotes({ division }: { division: string }) {
  const yearsWithVotes = await db
    .select({
      year: sql<number>`DISTINCT ${weeklyFinalRankings.year}`,
    })
    .from(weeklyFinalRankings)
    .where(sql`${weeklyFinalRankings.division} = ${division}`)
    .orderBy(sql`${weeklyFinalRankings.year} DESC`)

  return yearsWithVotes
}


But it just feels weird importing the schema to use it.
image.png
Was this page helpful?