MySQL between – Ways to use it with 3 examples

MySQL Between operator

  • MySQL supports different logical operators in queries and Between is one of those operators.
  • The Between is used in the Where clause.
  • You have to specify two values in the between MySQL operator. A minimum and a maximum value.
  • These two values can be characters, dates or numbers.
  • For example between 0 AND 10 ; between h AND z ; between 1/1/2012 AND 1/6/2013.
  • The returned rows while using the between operator includes minimum and maximum values.

How to use Between operator

The syntax of using the Between operator is:

Select * from table_name

Where col_name BETWEEN val1 AND val2

Where val1 and val2 can be numbers, characters or dates.

Examples of the between operator

In our examples of between operator, we will use our created table, tbl_employee, that contains employees information. The table contains five fields including a primary key as shown below:

A between operator example with numbers

In this example, we are using two numbers in between operator. The query and output of the query can be seen by clicking the link below:

An example with characters

In this example, we will use two characters in the between clause. The query will return employees data whom names are starting and ending by the given characters:

The between query will be:

Between with dates example

Now we will use two dates in our query of between operator. The query will return records of employees whom joining date is between two given dates as shown below:

The MySQL between dates query will be:

Also see MySQL select

Was this article helpful?

Related Articles

Leave A Comment?