SQL AND

Starting here? This lesson is part of a full-length tutorial in using SQL for Data Analysis. Check out the beginning.

In this lesson we'll cover:

The SQL AND operator

AND is a logical operator in SQL that allows you to select only rows that satisfy two conditions. Using data from the Billboard Music Charts, the following query will return all rows for top-10 recordings in 2012.

SELECT *
  FROM tutorial.billboard_top_100_year_end
 WHERE year = 2012 AND year_rank <= 10

You can use SQL's AND operator with additional AND statements or any other comparison operator, as many times as you want. If you run this query, you'll notice that all of the requirements are satisfied.

SELECT *
  FROM tutorial.billboard_top_100_year_end
 WHERE year = 2012
   AND year_rank <= 10
   AND "group_name" ILIKE '%feat%'

You can see that this example is spaced out onto multiple lines—a good way to make long WHERE clauses more readable.

Sharpen your SQL skills

white-wave
SQL Practice Icon

Practice Problem


Write a query that surfaces all rows for top-10 hits for which Ludacris is part of the Group.

Try it out

SQL Query Editor


Available tables:
Try running the sample queries or write your own!