Filtering and searching data

In a table with lots of rows, we will probably want to restrict the number of rows that we retrieve. We can do this using one or more WHERE clauses. When filtering, we can use either full and exact column values or partial values.

Filtering by exact values

When filtering by exact values, we use the full value of a column. For example, a WHERE clause to retrieve data about everyone born on or after January 1, 1970 is given as follows:

WHERE birthday >= '1970-01-01'

The output will look similar to the following:

MariaDB [test]> SELECT * FROM employees 
    -> WHERE birthday >= '1970-01-01'; 
+----+----------------+---------------+-----------+------------+ 
| id | surname        | givenname     | pref_name | birthday   | 
+----+----------------+---------------+-----------+------------+ ...

Get Getting Started with MariaDB - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.