SQL WHERE statement

The SQL SELECT WHERE statement is used to retrieve data from a database table based on a specific condition. The WHERE clause is used to filter the result set, and only the rows that meet the specified condition are returned.

Syntax for a SELECT WHERE statement

1SELECT column1, column2, ... columnN 2FROM table_name 3WHERE condition;

In this syntax, column1, column2, ... columnN are the names of the columns that you want to retrieve, table_name is the name of the table from which you want to retrieve the data, and condition is the condition that the rows must meet in order to be returned.

For example, consider a table named customers that contains the following data:

1+----+-------+--------+ 2| id | name | city | 3+----+-------+--------+ 4| 1 | William | Boston | 5| 2 | Mike | Paris | 6| 3 | Max | Berlin | 7| 4 | Alice | Paris | 8+----+-------+--------+

If you want to retrieve only the rows where the city is Paris, you can use the following SELECT WHERE statement:

1SELECT name, city 2FROM customers 3WHERE city = 'Paris';

The result set of this statement will be:

1+-------+-------+ 2| name | city | 3+-------+-------+ 4| Mike | Paris | 5| Alice | Paris | 6+-------+-------+

As you can see, only the rows where the city is Paris are returned.