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

Inbuilt functions

MySQL provides numerous inbuilt functions. You have already used the CURDATE() function to get the current date.

You can use the functions in the WHERE clause:

mysql> SELECT * FROM employees WHERE hire_date = CURDATE();
  • For example, the following function gives the date from exactly one week ago:
mysql> SELECT DATE_ADD(CURDATE(), INTERVAL -7 DAY) AS '7 Days Ago';
  • Add two strings:
mysql> SELECT CONCAT(first_name, ' ', last_name) FROM employees LIMIT 1;+------------------------------------+| CONCAT(first_name, ' ', last_name) |+------------------------------------+| Aamer Anger                        |+------------------------------------+1 row in set (0.00 sec)

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