O'Reilly logo

MySQL 8 Cookbook by Karthik Appigatla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Simple pattern matching

You can use the LIKE operator. Use underscore (_) for matching exactly one character. Use % for matching any number of characters.

  • Find the count of all employees whose first name starts with Christ:
mysql> SELECT COUNT(*) FROM employees WHERE first_name LIKE 'christ%';+----------+| COUNT(*) |+----------+|     1157 |+----------+1 row in set (0.06 sec)
  • Find the count of all employees whose first name starts with Christ and ends with ed:
mysql> SELECT COUNT(*) FROM employees WHERE first_name LIKE 'christ%ed';+----------+| COUNT(*) |+----------+|      228 |+----------+1 row in set (0.06 sec)
  • Find the count of all employees whose first name contains sri:
mysql> SELECT COUNT(*) FROM employees WHERE first_name LIKE '%sri%'; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required