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 and BETWEEN Operators in SQL 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: LIKE in SQL BETWEEN in SQL Watch this Like and Between operators in SQL [videothumb class=\"col-md-12\" id=\"jerWdB2j8xk\" alt=\"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.

Interested in learning SQL? Enroll in our SQL Training now!

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_';

Want to get certified in SQL! Learn from our SQL expert and do excel in your career with intellipaat’s SQL certification.

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;

Visit our SQL Community to get answers to all your queries!

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.

Get familiar with the top SQL Interview Questions to get a head start in your career!

Leave a Reply

Your email address will not be published. Required fields are marked *