SQL WHERE Tutorial

SQL Tutorial: WHERE Statement with Example

Delve into the specifications of SQL's WHERE statement and its practical application in data filtration for careers in data analysis and database management. Learn how its correct implementation, with precise syntax, can ease data retrieval by setting specific conditions.

Key Insights

  • The WHERE statement, in SQL, is a tool for data filtration from a given table.
  • This statement functions by setting a specific condition that needs to be met in order for data records to be pulled out.
  • The correct syntax for using a WHERE statement is: SELECT * FROM table WHERE condition.
  • Real-world application of WHERE statement can be seen in data management for a basketball league where records of each player's team and basic statistics are kept.
  • To retrieve players with more than 10 points in the league, an SQL query using WHERE statement can be employed.
  • Running the SQL query with the WHERE statement correctly filters and presents the desired data based on the set condition.

How WHERE Works

  • Filters Rows

    Sets a condition that data records must meet to be returned.

  • Syntax

    SELECT * FROM table WHERE condition

  • Common Use

    Finding players with more than 10 points — SELECT * FROM stats WHERE points > 10;

  • Combine with AND/OR

    WHERE points > 10 AND team = 'A' filters on multiple criteria.

WHERE Statement

  • The WHERE statement is used to filter data from our table.

  • It sets a condition to be met for data records to be retrieved.

  • Syntax: SELECT * FROM table WHERE condition

Example

Let’s say we have a basketball league and we keep records of each player, which team they are on, and their basic statistics.

Stats Table

If we wanted to use a SQL query to find all the players with more than 10 points, we would write the following:

SQL Bootcamp: Live & Hands-on, In NYC or Online, Learn From Experts, Free Retake, Small Class Sizes,  1-on-1 Bonus Training. Named a Top Bootcamp by Forbes, Fortune, & Time Out. Noble Desktop. Learn More.

SQL WHERE statement

Once we hit ENTER and run, our result should be as follows:

SQL WHERE Result

Learn more in these courses

How to Learn SQL

Master SQL with hands-on training. SQL is one of the most in-demand programming languages and is used across a variety of professions.

Yelp Facebook LinkedIn YouTube Twitter Instagram