

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to use % wildcard correctly in MySQL?
You can use Like operator for working with % wildcard. The syntax is as follows
select *from yourTableName where yourColumName Like ‘condition%’;
To understand the above concept, let us first create a table. The query to create a table
mysql> create table SearchDemo -> ( -> Name varchar(100), -> LoginId varchar(100) -> ); Query OK, 0 rows affected (1.15 sec)
Insert some records in the table using insert command. The query is as follows
mysql> insert into SearchDemo values('John','1_1'); Query OK, 1 row affected (0.19 sec) mysql> insert into SearchDemo values('Johnson','1_2'); Query OK, 1 row affected (0.19 sec) mysql> insert into SearchDemo values('Carol','2_1'); Query OK, 1 row affected (0.12 sec) mysql> insert into SearchDemo values('Bob','11_1'); Query OK, 1 row affected (0.19 sec) mysql> insert into SearchDemo values('Sam','11_2'); Query OK, 1 row affected (0.25 sec) mysql> insert into SearchDemo values('Mike','21_1'); Query OK, 1 row affected (0.22 sec)
Display all records from the table using select statement. The query is as follows
mysql> select *from SearchDemo;
The following is the output
+---------+---------+ | Name | LoginId | +---------+---------+ | John | 1_1 | | Johnson | 1_2 | | Carol | 2_1 | | Bob | 11_1 | | Sam | 11_2 | | Mike | 21_1 | +---------+---------+ 6 rows in set (0.00 sec)
The % is a type of wildcard that represents zero, one, or multiple characters. The query is as follows using the % wildcard
mysql> select *from SearchDemo -> where LoginId Like '2%';
The following is the output
+-------+---------+ | Name | LoginId | +-------+---------+ | Carol | 2_1 | | Mike | 21_1 | +-------+---------+ 2 rows in set (0.00 sec)
- Related Questions & Answers
- How to correctly use WITH ROLLUP in MySQL?
- How to correctly use DELIMITER in a MySQL stored procedure?
- How to use wildcard in Python regular expression?
- How to use save() correctly in MongoDB?
- How to correctly enclose subquery in MySQL?
- How to correctly use delimiter in a MySQL stored procedure and insert values?
- How to correctly use INSERT INTO … SELECT in MySQL to avoid Error 1064?
- How to use formatting with printf() correctly in Java?
- How to apply CROSS JOIN correctly in MySQL?
- How to use the wildcard character (*) in Get-ChildItem in PowerShell?
- How to use quotes correctly while using LIKE with search variable in MySQL in Java?
- How to correctly implement conditions in MySQL stored procedure?
- Use delimiter correctly in a MySQL stored procedure to avoid BEGIN/END statements errors
- Resolve ERROR 1111 (HY000): Invalid use of group function in MySQL? How to correctly use aggregate function with where clause?
- New line separator doesn't work for group_concat function in MySQL? How to use it correctly?
Advertisements