© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•3y ago•
10 replies
ericmartinezr

How to use inner join with rqb?

Hello there!

Having the following schema

export const proyectos = mysqlTable('proyecto', {
  codigo: int('codigo').primaryKey()
});

export const plataformas = mysqlTable(
  'plataforma',
  {
    codigo: int('codigo').notNull(),
    plataforma: int('plataforma').notNull()
  },
  table => {
    return {
      pk: primaryKey({ columns: [table.codigo, table.plataforma] })
    };
  }
);

export const plataformaMantenedor = mysqlTable('plataforma_mantenedor', {
  id: int('id').primaryKey(),
  nombre: varchar('nombre', { length: 25 }).notNull()
});

export const proyectosRelations = relations(proyectos, ({ many }) => ({
  plataformas: many(plataformas)
}));

export const plataformaRelations = relations(plataformas, ({ one }) => ({
  proyectos: one(proyectos, {
    fields: [plataformas.codigo],
    references: [proyectos.codigo]
  }),
  plataformaMantenedor: one(plataformaMantenedor, {
    fields: [plataformas.plataforma],
    references: [plataformaMantenedor.id]
  })
}));
export const proyectos = mysqlTable('proyecto', {
  codigo: int('codigo').primaryKey()
});

export const plataformas = mysqlTable(
  'plataforma',
  {
    codigo: int('codigo').notNull(),
    plataforma: int('plataforma').notNull()
  },
  table => {
    return {
      pk: primaryKey({ columns: [table.codigo, table.plataforma] })
    };
  }
);

export const plataformaMantenedor = mysqlTable('plataforma_mantenedor', {
  id: int('id').primaryKey(),
  nombre: varchar('nombre', { length: 25 }).notNull()
});

export const proyectosRelations = relations(proyectos, ({ many }) => ({
  plataformas: many(plataformas)
}));

export const plataformaRelations = relations(plataformas, ({ one }) => ({
  proyectos: one(proyectos, {
    fields: [plataformas.codigo],
    references: [proyectos.codigo]
  }),
  plataformaMantenedor: one(plataformaMantenedor, {
    fields: [plataformas.plataforma],
    references: [plataformaMantenedor.id]
  })
}));


This query gives me all the "proyectos" when I actually want only those that match "plataformas" with id (aka plataforma) "[10,12]"
because drizzle is using LEFT JOIN to join the tables.

let s = this.db.query.proyectos
      .findMany({
        with: {
          plataformas: {
            with: {
              plataformaMantenedor: true
            },
            where: _ => inArray(plataformas.plataforma, [10, 12])
          }
        },

        limit: 25,
        offset: 0
      })
let s = this.db.query.proyectos
      .findMany({
        with: {
          plataformas: {
            with: {
              plataformaMantenedor: true
            },
            where: _ => inArray(plataformas.plataforma, [10, 12])
          }
        },

        limit: 25,
        offset: 0
      })


Is there a way to use "inner join" to filter all the rows with the inner where?
I'm still learning drizzle so I may be making a mistake anywhere else.
I hope I made myself clear enough (english is not my main language)
Thanks in advance!
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Update with inner join?
Drizzle TeamDTDrizzle Team / help
3y ago
Inner join not working correctly
Drizzle TeamDTDrizzle Team / help
9mo ago
using rqb with pgSchema
Drizzle TeamDTDrizzle Team / help
13mo ago
Does the normal query use inner join under the hood?
Drizzle TeamDTDrizzle Team / help
11mo ago