bing
Flat 10% & upto 50% off + 10% Cashback + Free additional Courses. Hurry up
×
UPTO
50%
OFF!
Intellipaat
Intellipaat

LIKE and BETWEEN in SQL

LIKE and BETWEEN operators in SQL are used to compare values in a database. In this tutorial section, we will discuss on:

Watch this Like and Between operators in SQL

LIKE Operator in SQL

The LIKE in SQL is used to extract records where a particular pattern is present. For example, imagine that we want to extract a person’s name that includes ‘john’. So, if there are three people with names johnathan, johnny, and marcus, then with help of the LIKE in SQL, we can extract records where the names are johnathan and johnny, since they have the required pattern present in them.
The LIKE in SQL is used in conjunction with wildcard characters, such as:

  • Percentage symbol: It is a substitution for zero, one, or more characters.
  • Underscore symbol: It is a substitution for a single character.

SQL Like Syntax

SELECT column_list
FROM tablename
WHERE column_N LIKE ‘_xxxxx%’;

where SELECT, FROM, WHERE, and LIKE are the keywords, column_list is the list of columns, tablename is the name of the table, column_N is the column name, and there is a pattern followed by a semicolon.

Let’s do some operations with the LIKE query in SQL. Extract all records where the employee name starts with the letter ‘J’

Select * from employee where e_name LIKE 'j%';

LIKE OperatorAfter writing the query, click on the execute button to check for errors. Once the query is executed, a message appears like ‘Commands completed successfully’.

Now, let’s extract all records where the employee age is in twenties.

Select * from employee where e_age LIKE '2_';

LIKE Operator step 2

After writing the query, click on the execute button to check for errors. Once the query is executed, a message appears like ‘Commands completed successfully’

BETWEEN in SQL

The BETWEEN operator in SQL is used to select values within a given range. For example, to extract only those records where the age of the person is between 20 and 25, we have to use the SQL BETWEEN operator.

SQL Between Syntax

SELECT column_list
FROM tablename
Where column_N BETWEEN val1 AND val2;

where SELECT, FROM, WHERE, BETWEEN, and AND are the keywords, column_list is a list of columns, tablename is the name of the table, column_N is the column name, and val1 is the minimum value of the range and val2 is the maximum value of the range, followed by a semicolon. Let’s, now, display employees aging between 25 and 35 from the employee table

Select * From employee where e_age BETWEEN 25 AND 35;

After writing the query, click on the execute button to check for errors. Once the query is executed, the table appears.

Let’s display salaries of employees between $60,000 and $120,000 from the employee table

Select * From employee where e_salary BETWEEN 60000 AND 1200000;

BETWEEN Operator 3

After writing the query, click on the execute button to check for errors. Once the query is executed, the table appears.

Well, this brings us to the end of this tutorial section. Now, you’re ready to get started with using LIKE in SQL and BETWEEN in SQL for comparing the values in your database.

Previous Next

Download Interview Questions asked by top MNCs in 2019?

"0 Responses on LIKE and BETWEEN Operators in SQL"

    Leave a Message

    100% Secure Payments. All major credit & debit cards accepted Or Pay by Paypal.
    top

    Sales Offer

    Sign Up or Login to view the Free LIKE and BETWEEN Operators in SQL.