Subquery in Delete

what is the correct way to write a delete statement with a subquery?

example not working:

      const department = db
        .select()
        .from(baseDepartment)
        .where(eq(baseDepartment.id, 21))
        .as("sq");

      const a = await db
        .with(department)
        .delete(baseDepartment)
        .where(eq(baseDepartment.id, department.id));

error I am getting is: Missing from cause value for "sq"
Was this page helpful?