IvanM
IvanM

Reputation: 3053

Knex not equal <> operator query

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

Upvotes: 6

Views: 17570

Answers (2)

Sinux
Sinux

Reputation: 1808

<> 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.

Upvotes: 9

martin.macko.47
martin.macko.47

Reputation: 897

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

Upvotes: 8

Related Questions