SQL

SQL Where

SQL Where

This page covers SQL Where statement.

The previous tutorials briefly explored the concept of the “where” statement.

In SQL, the “where” statement is one of the most used statements, as it works well with many other SQL statements.

Its usage encompasses the extraction of pre-specified data. In other words, it operates as a filter.

This tutorial covers:

  • filtering data

Let’s use the table “student_info” from the previous tutorials.

idfirstNamelastNameage
1JohnSmith21
2PatrickCasey26
3SamAdams19
4MikeGarciaNULL
5PatrickDumont21

Where

The “where” statement can filter information in various forms.

In further tutorials, we will see the combination of “where” and other statements.

This statements is placed after the main statements, such as “select”, “update”, “delete”, and so on.

The following is an example of filtering records with a specific name.

SELECT * FROM student_info
WHERE lastName='Adams';

Please note that if there is no data that match the filter’s criteria, nothing will show as an output.

Let’s se the result of the above statement.

idfirstNamelastNameage
3SamAdams19

We can filter through any data inside the table.

Below is an instance of filtering student ids. Please note that integers (numbers) do not need quotes.

SELECT * FROM student_info
WHERE id=2;

Let’s check the outcome.

idfirstNamelastNameage
2PatrickCasey26

The above scenarios display results with only a single record.

But the “where” statement can show unlimited result points, as long as the filter’s pre-specified conditions match the information.

The following is an example of showing all 21 years old students.

SELECT * FROM student_info
WHERE age=21;
idfirstNamelastNameage
1JohnSmith21
5PatrickDumont21

The outcome shows 2 records. Both students match the condition of age=21.


Next: SQL Alias