Starting here? This lesson is part of a full-length tutorial in using SQL for Data Analysis. Check out the beginning.
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.
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.
WHERE year = 2012
AND year_rank <= 10
AND "group" 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
Write a query that surfaces all rows for top-10 hits for which Ludacris is part of the Group.
Write a query that surfaces the top-ranked records in 1990, 2000, and 2010
Write a query that lists all songs from the 1960s with "love" in the title.