Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Knex not equal <> operator query

Tags:

sql

knex.js

I'm trying to make query like:

"SELECT * ... WHERE deleted <> 1"

I found one solution:

.whereRaw("deleted <> ?", [1]);

But can I use .where (.whereNot) methods for this ?

Thank you

like image 796
IvanM Avatar asked Aug 27 '26 20:08

IvanM


2 Answers

<> and != both mean not equal, and != is an alias for the standard <> operator.

!= may not exist in old version of MySQL, but normally you have no need to pay attention to this, as for knex documentation, it's just an example which tried to explain knex.raw...

whereNot is OK.

like image 65
Sinux Avatar answered Aug 30 '26 10:08

Sinux


You can use directly knex.js whereNot method as in the following:

knex('table_name').whereNot('deleted', 1)

which translates to:

SELECT * from table_name WHERE NOT deleted = 1
like image 22
martin.macko.47 Avatar answered Aug 30 '26 10:08

martin.macko.47



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!