Querying with conditions

Learn to Code Today!

Learn 10x faster: coding, no-code and data skills. Join millions of users mastering new tech skills and accelerating their career with Enki.
Get started

This is part of “An intro to SQL” series of posts, with content from the Enki app. If you stumbled upon this, you can start from the beginning.

Aside from columns, you might also want to restrict the number of records (rows) returned.

Introducing: the WHERE keyword! Here it is in action:

When added to a SQL SELECT statement, WHERE allows us to select rows in a table based on conditions you set.

The conditional statement that follows WHERE is evaluated for each row. If it’s evaluated as true, the row will be included in the query result.

Conditional statements can include comparison operators like:

Here’s another pokemon table:

Let’s look up all the info on the ”Caterpie” pokemon:

Which results in:

No prizes for guessing the query which gives the name and hp of all pokemon with attack greater than or equal to 30:

The results are:

Text needs to be enclosed within quotation marks (’text’), while integers¹ (and other numerical types) should not have quotes.

If you want to try these queries yourself, you can find the playground link in the Learn More section.

Footnotes

[1] An integer is nothing more than a whole number. For example, 1, 12345, and -999 are all integers.

Learn More

About Enki

  • Fully personalized online up-skilling
  • Unlimited AI coaching
  • Designed by Silicon Valley experts

More articles

Meet your AI-enabled coach

Professional athletes have a coach for every aspect of their performance. Why can’t you for your work? Enki’s AI-powered coaching on-demand - combined with state of the art, structured learning content - makes this a reality.
1
1:1 AI Coaching
How do I remove duplicate emails?
Convert the list to a set and back to a list. Sets automatically remove duplicates.
2
Personalized Exercises
3
Interactive practice

Unlock full access to all skills on Enki with a 7-day free trial

Get started