Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

541
Views
How to query id not in condition with another table typeorm

Here is the query

SELECT * from tableA WHERE tableA.id NOT IN (SELECT tableB.a_id FROM tableB);

Same query how to write using TypeORM typescript? Below is code, I tried which is not working

this.createQueryBuilder('tableA')
.where(`tableA.id != :id`, { id })
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

const tableBqry = tableBRepository
       .createQueryBuilder('tableB')
       .select("tableb_id");

const tableAqry = tableARepository
       .createQueryBuilder('tableA')
       .where("tableA.id NOT IN (" + tableBqry.getSql() + ")");

const results = await tableAqry.getMany();

This method will work fine for the above-mentioned problem.

over 4 years ago · Santiago Trujillo Report

0

You can select IDs from tableB first, and then use the IDs you've got (I assume that they are mapped and stored in var ids: string[]) to make a query for tableA.

this.createQueryBuilder('tableA')
  .where(`tableA.id <> ALL(:ids)`, { ids })
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!