The LIKE and IN comparison operators in SQL

Previous articles by TipsMake have introduced you to common commands and clauses in SQL. Todays article will continue by introducing you to the LIKE and IN comparison operators in SQL.

Several comparison keywords are used in SQL to enhance the searchability of an SQL query, including " BETWEEN . AND ", " IS NULL ", " LIKE ", and " IN". This article from TipsMake will introduce you to the BETWEEN . AND , IS NULL , LIKE , and IN comparison operators in SQL.

The list of comparison operators in SQL includes BETWEEN.AND, IS NULL, LIKE, and IN:

The LIKE operator in SQL

The LIKE operator in SQL is used to list all rows in a table whose values ​​match a specified pattern. The LIKE operator is particularly useful if you want to search for rows that match a specified pattern, or if you don't know the entire value. In this case, use the % wildcard.

Example of the LIKE operator in SQL

Example 1

To select all students in a class whose names begin with the letter 'S', the LIKE statement is written as follows:

SELECT first_name, last_name

FROM student_details

WHERE first_name LIKE 'S%';

The output will be in the following format:

The SELECT command searches for all rows in the name column that contain names starting with the letter S, with the rest being any other character.

Alternatively, you can use the underscore (_) wildcard with the LIKE operator in SQL. In a search string, underscores represent a single character.

Example 2

To display all names that begin with the letter "a", the LIKE statement in SQL is written as follows:

SELECT first_name, last_name

FROM student_details

WHERE first_name LIKE '_a%';

The output will be in the following format:

Some notes on the LIKE operator in SQL

An underscore acts as a placeholder for a character. Therefore, you can use multiple underscores.

For example, "__i%" has two underscores to the left, or "S__j%" has two underscores between the characters 'S' and 'i'.

The BETWEEN . AND operator in SQL

The BETWEEN . AND operator in SQL is used to compare data for a range of values.

For example, the BETWEEN . AND operator in SQL.

To find the names of students aged 10 to 15, the BETWEEN . AND statement in SQL is written as follows:

SELECT first_name, last_name, age

FROM student_details

WHERE age BETWEEN 10 AND 15

The output will be in the following format:

The IN operator in SQL

The IN operator in SQL is used when you want to compare a column with multiple values. It's similar to the OR condition in SQL.

Example of the IN operator in SQL

If you want to find the names of students registered for math or science, the IN command in SQL is written as follows:

SELECT first_name, last_name, subject

FROM student_details

WHERE subject IN ('Maths', 'Science');

You can add many different subjects to the list such as ('maths', 'science', 'history').

Note regarding the IN statement in SQL

The data is used for case-sensitive comparison.

The IS NULL operator in SQL

A column's value is NULL if it doesn't exist. The IS NULL operator in SQL is used to display all rows containing columns with no values.

Example of the IS NULL operator in SQL

If you want to find the names of students who did not participate in any games, the IS NULL statement in SQL is written as follows:

SELECT first_name, last_name

FROM student_details

WHERE games IS NULL

If all students participate in the game, no output will be returned. Otherwise, it will return the names of the students who did not participate in the game.


In summary, TipsMake has introduced you to some comparison operators, including BETWEEN.AND, IS NULL, LIKE, and IN in SQL. To learn more about clauses and commands such as RENAME, UPDATE, CREATE, etc., or clauses like WHERE, etc., in SQL, you can refer to some articles on TipsMake, such as " Installing SQL Server on Ubuntu, " to set up a SQL Server environment on your computer.

Other SQL articles
  • The CREATE command in SQL

    sql là viết tắt của structured query language, là ngôn ngữ lập trình được sử dụng để liên lạc và vận dụng cơ sở dữ liệu, trong bài viết dưới đây tipsmake sẽ giới thiệu lệnh create trong sql giúp bạn nắm rõ cú pháp cũng như cách sử dụng.
  • GRANT, REVOKE in SQL

    các lệnh dcl trong sql được sử dụng để thực thi bảo mật cơ sở dữ liệu trong môi trường cơ sở dữ liệu người dùng. lệnh grant, revoke trong sql là 2 kiểu lệnh dcl. Để tìm hiểu rõ hơn về lệnh dcl cũng như lệnh grant, revoke trong sql, bạn đọc cùng tham khảo bài viết dưới đây của tipsmake.
  • The JOINS command in SQL

    thông thường, lệnh joins trong sql được sử dụng để kết nối các thông tin trong các bảng khác nhau, điều kiện joins là một phần trong truy vấn sql để truy xuất các hàng từ 2 bảng trở lên.
  • How to deploy SQL Server via PowerShell DSC

    hôm nay, tipsmake sẽ hướng dẫn các bạn cách triển khai sql server thông qua powershell dsc giúp bạn có thể sử dụng tính năng powershell mới quan lý cơ sở hạ tầng trong cơ sở, trên dịch vụ đám mây hiệu quả, dễ dàng.
  • How to create, validate, and modify the Identity column in Microsoft SQL Server

    microsoft sql server được tích hợp sẵn cột identity, được sử dụng để tạo ra các giá trị quan trọng. nó có thể tham chiếu nhưng một trường autonumber trong microsoft access hoặc một dãy trong oracle. bài viết dưới đây tipsmake sẽ hướng dẫn bạn cách tạo, kiểm tra và thay đổi cột indentity trên microsoft sql server.
  • How to log in to SQL Server if the SA account is disabled.

    trong trường hợp nếu tài khoản sa bị vô hiệu hóa và bạn không thể đăng nhập sql server. bài viết này tipsmake sẽ hướng dẫn bạn cách đăng nhập sql server nếu tài khoản sa bị vô hiệu hóa.
Category

System

Windows XP

Windows Server 2012

Windows 8

Windows 7

Windows 10

Wifi tips

Virus Removal - Spyware

Speed ​​up the computer

Server

Security solution

Mail Server

LAN - WAN

Ghost - Install Win

Fix computer error

Configure Router Switch

Computer wallpaper

Computer security

Mac OS X

Mac OS System software

Mac OS Security

Mac OS Office application

Mac OS Email Management

Mac OS Data - File

Mac hardware

Hardware

USB - Flash Drive

Speaker headset

Printer

PC hardware

Network equipment

Laptop hardware

Computer components

Advice Computer

Game

PC game

Online game

Mobile Game

Pokemon GO

information

Technology story

Technology comments

Quiz technology

New technology

British talent technology

Attack the network

Artificial intelligence

Technology

Smart watches

Raspberry Pi

Linux

Camera

Basic knowledge

Banking services

SEO tips

Science

Strange story

Space Science

Scientific invention

Science Story

Science photo

Science and technology

Medicine

Health Care

Fun science

Environment

Discover science

Discover nature

Archeology

Life

Travel Experience

Tips

Raise up child

Make up

Life skills

Home Care

Entertainment

DIY Handmade

Cuisine

Christmas

Application

Web Email

Website - Blog

Web browser

Support Download - Upload

Software conversion

Social Network

Simulator software

Online payment

Office information

Music Software

Map and Positioning

Installation - Uninstall

Graphic design

Free - Discount

Email reader

Edit video

Edit photo

Compress and Decompress

Chat, Text, Call

Archive - Share

Electric

Water heater

Washing machine

Television

Machine tool

Fridge

Fans

Air conditioning

Program

Unix and Linux

SQL Server

SQL

Python

Programming C

PHP

NodeJS

MongoDB

jQuery

JavaScript

HTTP

HTML

Git

Database

Data structure and algorithm

CSS and CSS3

C ++

C #

AngularJS

Mobile

Wallpapers and Ringtones

Tricks application

Take and process photos

Storage - Sync

Security and Virus Removal

Personalized

Online Social Network

Map

Manage and edit Video

Data

Chat - Call - Text

Browser and Add-on

Basic setup