Hello Friends,

Welcome To Infinitbility!

This article based on sequelize operators, here we will learn about How many types of basics sequelize operators and how we can use in query.

We use `greater than`

, `less than`

, `Greater than or equal`

, `Less than or equal`

, `Not equal`

, `Equal `

, sign in sql but in sequelize we use as Operators to done this types of query. One more thing sequelize Operators also use for `and`

and `or`

types of query.

Sequelize more then this operators but we will cover in specfic post for those now we will cover only basics Operators.

Let’s start today article *Sequelize Operators Example with query*

Table of content

- Equal Operator
- Not equal Operator
- Greater than Operator
- Less than Operator
- Greater than or equal Operator
- Less than or equal Operator
- And Operator
- Or Operator

For using operator We have to first import `Op`

form Sequelize like below.

1const { Op } = require("sequelize");

## Equal Operator ( = )

The Equal Operator use for check same value available in table or not in sql we use equal to sign ( = ) but in sequelize we use `Op.eq`

in query like below example.

1Pug.findAll({2 where: {3 age: {4 [Op.eq]: 75 }6 }7})

## Not equal Operator ( != )

The Not equal Operator use for filter data those value available in your table. In sql we use not equal to sign ( != ) but in sequelize we use `Op.ne`

in query like below example.

1Pug.findAll({2 where: {3 age: {4 [Op.ne]: 75 }6 }7})

## Greater than Operator ( > )

The Greater than Operator use get those data have more value compare to search value in sql we us greater than sign ( > ) for this but in sequelize we use `Op.gt`

like below example.

1Pug.findAll({2 where: {3 age: {4 [Op.gt]: 75 }6 }7})

## Less than Operator ( < )

The Less than Operator use get those data have less value compare to search value in sql we us Less than sign ( < ) for this but in sequelize we use `Op.lt`

like below example.

1Pug.findAll({2 where: {3 age: {4 [Op.lt]: 75 }6 }7})

## Greater than or equal Operator ( >= )

The Greater than or equal Operator same like Greater than Operator but also check same value or not.

In sequelize we use `Op.gte`

to get same or greater value in search.

1Pug.findAll({2 where: {3 age: {4 [Op.gte]: 75 }6 }7})

## Less than or equal Operator ( <= )

The Less than or equal Operator same like Less than Operator but also check same value or not.

In sequelize we use `Op.lte`

to get same or less value in search.

1Pug.findAll({2 where: {3 age: {4 [Op.lte]: 75 }6 }7})

## And Operator ( And )

We use And Operator in sql simple like `and`

keyword but in sequelize we have to use `Op.and`

example like below.

1Pug.findAll({2 where: {3 [Op.and]: {4 age: 85 },6 [Op.and]: {7 is_active: 88 }9 }10})

It’s just example to use and Operator don’t go with query optimization.

## Or Operator ( or )

We use Or Operator in sql simple like `or`

keyword but in sequelize we have to use `Op.or`

example like below.

1Pug.findAll({2 where: {3 [Op.or]: {4 age: 85 },6 [Op.or]: {7 is_active: 88 }9 }10})

Subscribe Our Newsletter You will get monthly free programming book