In databases, can we filter the output of SQL queries to show only rows matching a certain criteria? [WHERE clause]

D. S. Pandit
2 min readFeb 5, 2020
Photo by Marc Babin on Unsplash

Disclaimer:

The author has attempted to share information / answer questions for beginner level readers based on the knowledge and experience gained by the author till the date of publishing. More accurate or latest information may exist. The readers seeking more detailed, more accurate or more recent information should refer other resources found appropriate by them.

The information given was commonly observed across various database products by the author, however, there may be some database products / brands / versions with different behavior.

In databases, can we filter the output of SQL queries to show only rows matching a certain criteria? [WHERE clause]

Yes. We can use WHERE clause in SQL statements and specify some conditions like say, “WHERE Dept_name = ‘Accounts’ “
WHERE clause can be used for SELECT, UPDATE and DELETE statements. If it is used with SELECT statement, then the output will only display the records which match the conditions specified in WHERE clause.*

* WHERE clause is very important while working with SQL statements. If WHERE clause is missed, all the rows will be included in the operation. If WHERE clause is incorrectly typed in DELETE or UPDATE statements, some rows can be unintentionally updated or deleted. Some application programs use “prepared statements” in which a string variable is used to build an SQL statement on the fly — in such programs, there should be enough validations to check that WHERE clause is properly added. Even for regular (hard-coded) SQL statements, the developer should be equally careful about WHERE clause. It is in general a good practice to review / test all applications and SQL statements and ensure that they are error-free before they hit production database.

--

--