Skip to content
Discussion options

You must be logged in to vote

Here's how you do this with drizzle:

const sq = db.select({ max: sql`max(${threadMessages.createdAt})` }).from(threadMessages).where(eq(threads.id, threadMessages.threadId));

const query = await db.select()
  .from(threads)
  .leftJoin(threadMessages, eq(threadMessages.threadId, threads.id))
  .where(or(
    eq(threadMessages.createdAt, sq),
    isNull(threadMessages.createdAt)
  ));

This might work. Let me know if it doesn't there might be other ways to do it.

Replies: 3 comments 6 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@tjapa
Comment options

@ghost
Comment options

Comment options

You must be logged in to vote
4 replies
@tjapa
Comment options

@tjapa
Comment options

@Angelelz
Comment options

Angelelz Jan 5, 2024
Collaborator

@tjapa
Comment options

Answer selected by tjapa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants