How to use subqueries with query

  const jobsDb = await db.query.jobs_table.findMany({
    where: notExists(
      db
        .select()
        .from(matches_table)
        .where(
          and(
            eq(matches_table.user_id, userId),
            eq(matches_table.job_id, jobs_table.id),
          ),
        ),
    ),
    with: {
      working_days: true,
      location: true,
      location_image_file: true,
      required_languages: true,
      required_skills: true,
      matches: true,
    },
    // orderBy: sql`RAND()`,
  });


Returns the error "invalid reference to FROM-clause entry for table jobs"

Suppose it's because it's not joining matches. Saw this image but not sure if this means that subqueries are just not acceptable.

Is there a way to make the implementation I want using queries? Can make this work with select but didn't want to make a massive function to parse everything in the correct schema.

Quite litteraly the only thing left in my API, would really appreciate some help
image.png
Was this page helpful?