×

SQL Wildcards

SQL WILDCARD CHARACTERS:

SQL wild card character is used to substitute zero or more characters of a string.

These characters are used with the “LIKE” operator.

Wild Card Characters in SQL:

  • %
  • _
  • []
  • ^
  • -

“%” :

It is used to represent the zero or more characters in a string.

Example:

Student Table

sidsnamesagesgenderPhonenumber
1Abhinav22Male9895678909
2Ramya24Female6687654634
3Preetham21Male9867546453
4Nethranand21Male7675643423
5Naveen23Male6567784532
6Harshita22Female9867546231
7Bindu26Female6563412768
8Nandhini23Female6785674839
9Hashish22Male9453215052
10Rahul21Male9998989898

Command For Selecting details of students from Student table whose name Starts with “N”

SQL Code:

Select * from student where sname LIKE ‘N%’;

Output:

sidsnamesagesgenderPhonenumber
4Nethranand21Male7675643423
5Naveen23Male6567784532
8Nandhini23Female6785674839

“_” :

       It is used to represent a single character.

Example:

      Student Table

sidsnamesagesgenderPhonenumber
1Abhinav22Male9895678909
2Ramya24Female6687654634
3Preetham21Male9867546453
4Nethranand21Male7675643423
5Naveen23Male6567784532
6Harshita22Female9867546231
7Bindu26Female6563412768
8Nandhini23Female6785674839
9Hashish22Male9453215052
10Rahul21Male9998989898

Command For Selecting details of students from Student table whose name ends with “a”

SQL Code:

Select * from student where sname LIKE ‘_%a’;

Output:

sidsnamesagesgenderPhonenumber
2Ramya24Female6687654634
6Harshita22Female9867546231

“[]”:

     It is used to represent any single character within the bracket.

Example:

      Student Table

sidsnamesagesgenderPhonenumber
1Abhinav22Male9895678909
2Ramya24Female6687654634
3Preetham21Male9867546453
4Nethranand21Male7675643423
5Naveen23Male6567784532
6Harshita22Female9867546231
7Bindu26Female6563412768
8Nandhini23Female6785674839
9Hashish22Male9453215052
10Rahul21Male9998989898

Command For Selecting details of students from Student table whose name ends with “a”

SQL Code:

Select * from student where sname LIKE ‘[NH]%a’;

Output:

sidsnamesagesgenderPhonenumber
4Nethranand21Male7675643423
5Naveen23Male6567784532
6Harshita22Female9867546231
8Nandhini23Female6785674839
9Hashish22Male9453215052

“!”:

      It represents the character that is not in the bracket.

Example:

      Student Table

sidsnamesagesgenderPhonenumber
1Abhinav22Male9895678909
2Ramya24Female6687654634
3Preetham21Male9867546453
4Nethranand21Male7675643423
5Naveen23Male6567784532
6Harshita22Female9867546231
7Bindu26Female6563412768
8Nandhini23Female6785674839
9Hashish22Male9453215052
10Rahul21Male9998989898

Command For Selecting details of students from the Student table whose name does not start with N and H

SQL Code:

Select * from student where sname LIKE “[!NH]%”;

Output:

sidsnamesagesgenderPhonenumber
1Abhinav22Male9895678909
2Ramya24Female6687654634
3Preetham21Male9867546453
7Bindu26Female6563412768
10Rahul21Male9998989898

“-“ :

     It represents the character within the given range which is present in brackets.

Example:

      Student Table

sidsnamesagesgenderPhonenumber
1Abhinav22Male9895678909
2Ramya24Female6687654634
3Preetham21Male9867546453
4Nethranand21Male7675643423
5Naveen23Male6567784532
6Harshita22Female9867546231
7Bindu26Female6563412768
8Nandhini23Female6785674839
9Hashish22Male9453215052
10Rahul21Male9998989898

Command For Selecting details of students from Student table whose name in which first character lies in the range [A-R].

SQL Code:

Select * from student where sname LIKE ‘[A-R]%’;

Output:

sidsnamesagesgenderPhonenumber
1Abhinav22Male9895678909
2Ramya24Female6687654634
3Preetham21Male9867546453
4Nethranand21Male7675643423
5Naveen23Male6567784532
6Harshita22Female9867546231
7Bindu26Female6563412768
8Nandhini23Female6785674839
9Hashish22Male9453215052
10Rahul21Male9998989898

“#”:

     It represents the numeric character in a string.

Example:

      Student Table

sidsnamesagesgenderPhonenumber
1Abhinav‘22’Male9895678909
2Ramya‘24’Female6687654634
3Preetham‘21’Male9867546453
4Nethranand‘21’Male7675643423
5Naveen‘23’Male6567784532
6Harshita‘22’Female9867546231
7Bindu‘26’Female6563412768
8Nandhini‘23’Female6785674839
9Hashish‘22’Male9453215052
10Rahul‘21’Male9998989898

Command For Selecting details of students from Student table whose age in which first character is ‘2’.

SQL Code:

Select * from student where sname LIKE ‘2#’;

Output:

sidsnamesagesgenderPhonenumber
1Abhinav‘22’Male9895678909
2Ramya‘24’Female6687654634
3Preetham‘21’Male9867546453
4Nethranand‘21’Male7675643423
5Naveen‘23’Male6567784532
6Harshita‘22’Female9867546231
7Bindu‘26’Female6563412768
8Nandhini‘23’Female6785674839
9Hashish‘22’Male9453215052
10Rahul‘21’Male9998989898

Related Topics

SQL Left Join

The SQL Left Join query displays all the records from the table and displays similar records from the right table. The query displays zero records if it doesn’t find any...

4 minutes read.

SQL CREATE TABLE

In SQL tutorial, we learned and created different databases. To stores data in databases, we need to create a table. To create the table, we need to use CREATE TABLE...

5 minutes read.

SQL GROUP BY CLAUSE

The GROUP BY clause is used to arrange similar records into the groups in the Structured Query Language queries. The records are arranged with the help of functions which is...

4 minutes read.

Where Condition in SQL

WHERE clause is used with the Data Manipulation Language Command in SQL, the Data Manipulation Language commands are the SELECT statement, UPDATE statement, and DELETE statement. WHERE clause condition is an...

5 minutes read.

Difference between Delete, Drop and Truncate in SQL

What is the Delete command in SQL? In DML (Data Manipulation Language), we use the delete command that allows us to delete the some entries and modify the databases in SQL....

4 minutes read.

SQL Count

Structured Query Language Count() Function is used with Structured Query Language SELECT Statement. SQL Count() function returns the number of items that match the specified criteria in the SELECT statement. Count()...

2 minutes read.

SQL Auto Increment

As we all know, In SQL for unique identification, we assign a column with the primary key. But in some tables, we find difficult to differentiate a column as a...

5 minutes read.

SQL Data Definition Language

Data definition language directly effects on the structure/schema of the database. CREATE, ALTER, DROP are the commands of DDL.CREATE: Creates new database, table, or view of table.ALTER: Modifies the database or...

3 minutes read.

SQL WHERE Clause

The WHERE clause is a search filter that returns only true records. The WHERE clause chooses the selected records based on the given conditions. The WHERE clause is used with...

4 minutes read.

SQL VIEW

The SQL VIEW concept helps to hide the difficulty of the records and provides limitations to access to the database. The SQL view is similar to the SQL tables. In SQL...

7 minutes read.

SQL CRUD Operation

In any computer language, CRUD operation is a foundation. CRUD operation rules are applied in databases as well. These operations are the basic operations used to perform with any database...

7 minutes read.

How to use GROUP BY clause in SQL

In this SQL article, we will learn about the GROUP BY clause and how to use it in SQL. We will also discuss using the GROUP BY clause with the...

6 minutes read.

Check Constraint in SQL

The Check Constraint in SQL is the rule or set of rules used to limit the data range that can be entered in a table column. Check constraint is used...

8 minutes read.

SQL SELECT WHERE Clause

In this SQL section, we will help you understand the concept of the SQL SELECT WHERE clause with a few examples. The WHERE clause in SELECT query displays those records as...

5 minutes read.

Save Point in SQL

In SQL, the classification is done into 4 languages. They are Data Definition Language (DDL)Data Manipulation Language (DML)Transaction Control Language (TCL)Data Control Language (DCL) Save Point falls under the Transaction Control Language....

4 minutes read.

Pattern Matching in SQL

The LIKE in the Structured Query Language is a Logical Operator. The SQL LIKE is used within the WHERE clause in the SQL. This Like Operator is used with the...

5 minutes read.

How to Add Comments in SQL?

How to Add Comments in SQL Comments are text notes that are incorporated into the program to make the code easier to understand. In SQL, commenting is used to explain various sections...

2 minutes read.

SQL Aggregate Operators

In SQL, the aggregate operators perform a calculation on multiple rows or multiple values of a single column and give the output a single value. Here, multiple rows of data are...

4 minutes read.

SQL Arithmetic Operators

This page contains all the information, learn about SQL Arithmetic Operators concept in the SQL table with the help of examples. The Arithmetic Operators is used to perform mathematical calculations on...

5 minutes read.

SQL Except

In SQL, we probably use the JOIN clause to receive the combined result from one or more than one table. But sometimes, we want a result that contains data from...

4 minutes read.