Sitemap
Torera David-West

Torera David-West

The WHERE Clause in MySQL

2 min readJun 25, 2019

The WHERE Clause is used to filter only those records that are fulfilled by a specific condition given by the user, in other words, the SQL WHERE Clause is used to restrict the number of rows affected by a SELECT, UPDATE or DELETE query.

I find that the WHERE Clause is very useful and helps in improving a query’s run time. By filtering the data to only include the observations you need or a subset of the information you require for testing; it dramatically improves your query speed.

The basic syntax of the WHERE Clause is

SELECT Column1, Column2, ….

FROM Table_Name

WHERE Condition

Example

Let us consider the following table “Students” with five columns ‘FirstName’, ‘LastName’, ‘Age’, ‘Class’ and ‘Year’.

To select all the rows where the “Year” is “1”, we will use the following code:

Get Torera David-West’s stories in your inbox

Join Medium for free to get updates from this writer.

SELECT FirstName, LastName, Age, Class, Year

FROM Students

WHERE Year = 1;

This syntax will give the following result below:

Furthermore, a subquery can be written in a WHERE Clause to qualify a column against a set of rows.

An example of a syntax using subqueries in the WHERE Clause can be seen below. It uses the European soccer database called “Match”.

Press enter or click to view image in full size

For further information on the WHERE Clause please watch the video below.

--

--