ThoughtSpot acquires Mode to define the next generation of collaborative BI >>Learn More

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

Practice Problem

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

Try it out See the answer

Practice Problem

Write a query that surfaces the top-ranked records in 1990, 2000, and 2010.

Try it out See the answer

Practice Problem

Write a query that lists all songs from the 1960s with "love" in the title.

Try it out See the answer

Next Lesson

SQL OR

Get more from your data

Your team can be up and running in 30 minutes or less.