1

SELECT * FROM EMPLOYEE WHERE AGE>40 AND (LOCATION='Chennai' OR NOT LOCATION='Agra');

How to write something similar to the above query statement in ObjectionJS/Knex ORM ?

Sree Sajai
  • 75
  • 7
  • `LOCATION='Chennai' OR NOT LOCATION='Agra'` Why do you have OR in between these two? – Anil Parshi Nov 11 '21 at 05:26
  • *`LOCATION='Chennai' OR NOT LOCATION='Agra'`* - if 2nd condition part `NOT LOCATION='Agra'` is false/null then the 1st part `LOCATION='Chennai'` is false/null too. Hence 1st part is excess and must be removed. – Akina Nov 11 '21 at 06:23

2 Answers2

0

Is this you looking for?

SELECT * FROM EMPLOYEE WHERE AGE>40 AND (LOCATION='Chennai' OR LOCATION <> 'Agra');
UDS
  • 161
  • 1
  • 11
0

Assuming that you have model Employee then you can use Objection.js query

Employee.query()
        .select('*')
        .where('age', '>', 40)
        .where(builder => builder.where('location', 'Chennai')
                                 .orWhereNot('location', 'Agra')
        )

you can read more about Objection.js subqueries syntax here https://vincit.github.io/objection.js/recipes/subqueries.html

Dmytro Biletskyi
  • 1,833
  • 15
  • 21