Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Databases Modifying Data with SQL Deleting Data From a Database Deleting Data With SQL

Angela Poldervaart
Angela Poldervaart
3,192 Points

Challenge Task: Deleting Data with SQL

The task is:

Now we're using a database from a smartphone. It has a phone_book table. It has the columns id, first_name, last_name and phone. Delete all contacts with the first name of Jonathan and last name of Luna.

I don't know what I'm doing wrong:

DELETE FROM phone_book WHERE first_name = "Jonathan" AND last_name = "Luna";

DELETE FROM phone_book WHERE first_name = "Jonathan", last_name = "Luna";

I've tried both but both were wrong.

1 Answer

Steven Parker
Steven Parker
210,850 Points

You were right the first time. I even tested it by pasting your code line directly into the challenge and it passed.

Perhaps you are having a browser issue, try restarting your browser and see if that fixes it.

Angela Poldervaart
Angela Poldervaart
3,192 Points

Now it worked! Good to know that I wasn't wrong :)

Thank you Steven!

I don't understand why this works. The way I read the question, we may have several contacts with either that first name or last name. Using the AND operator requires that both conditions be met for the DELETE function to work. I tried separating the values with a comma hoping that would work, but it didn't until I used AND.

Steven Parker
Steven Parker
210,850 Points

As I told Angela, her first example is the correct syntax (using "AND" to combine comparisons). It's not correct to place a comma between two comparisons.