Skip to content

Where Clause

In this post, we’ll look at how to use the WHERE clause with the equals, like, greater than, and less than operators in the StackOverflow database, focusing on the USERS table.

Assume we want to find all users who joined Stack Overflow prior to January 1st, 2010. The following SQL query can be used:

SELECT * FROM Users
WHERE CreationDate < '2010-01-01';

In this query, we specify in the WHERE clause that only rows with a CreationDate less than January 1st, 2020 should be returned.

In the next query, we want to retrieve all users with reputations greater than or equal to 10,000. The following SQL query can be used:

SELECT * FROM Users
WHERE Reputation >= 10000;

We access the USERS table and use the WHERE clause to limit the rows that are returned to those where Reputation is greater than or equal to 10,000.

Let’s now say that we want to get a list of all users whose display names contain the word dev. The SQL query below can be used:

SELECT * FROM Users
WHERE DisplayName LIKE '%dev%';

The WHERE will retrieve only rows with the value “dev” in the DisplayName column.

After going through these queries, try writing some more queries using the WHERE clause!

Leave a Reply

Your email address will not be published. Required fields are marked *