Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialBlake Wood
1,396 PointsDeleting names
Question: 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.
My code (that is wrong) is:
DELETE FROM phone_book WHERE first_name = ("Jonathan" AND "Luna");
Please advise where i am going wrong.
9 Answers
HIDAYATULLAH ARGHANDABI
21,058 PointsDELETE FROM phone_book WHERE first_name = "Jonathan" AND last_name = "Luna";
Mike Costa
Courses Plus Student 26,362 PointsIf you're looking to delete a single contact with first_name of "Jonathan" and last_name of "Luna" then your query should be:
DELETE FROM phone_book WHERE first_name = "Jonathan" AND last_name = "Luna";
If you're trying to delete ALL Jonathan's and ALL Luna's from the phone book, your query should be:
DELETE FROM phone_book WHERE first_name = "Jonathan" OR last_name = "Luna";
Following all the other queries wouldn't achieve what you're trying to accomplish.
Thomas is correct that
DELETE FROM phone_book WHERE first_name in ("Jonathan", "Luna");
is the same as
DELETE FROM phone_book WHERE first_name = "Jonathan" OR first_name = "Luna";
But what that query will do is delete every contact with the first name of Jonathan, and the first name of Luna.
Hope this clears things up a bit.
Johan Treschow
1,598 PointsIt still doesn't work!!!
PLEASE HELP!!
Johan Treschow
1,598 PointsPLEASE HELP!!!
Thomas Nilsen
14,957 Pointstry
DELETE FROM phone_book WHERE first_name in ("Jonathan", "Luna");
Stewart Mandla Kohlisa
11,737 Pointsthis is the answer...
DELETE FROM phone_book WHERE first_name = "Jonathan" AND last_name = "Luna";
webcoder133
10,812 PointsDELETE FROM phone_book WHERE first_name LIKE "Jonathan%" AND last_name LIKE "%Luna";
Eyanjem Etta-Ashu
Full Stack JavaScript Techdegree Graduate 18,260 PointsIt says delete all contacts with first name Jonathan and last name Luna, i believe we are suppose to delete all instances of the names so below is the correct answer. DELETE FROM phone_book WHERE first_name LIKE "Jonathan%" AND last_name LIKE "%Luna";
Rashad Madison
Full Stack JavaScript Techdegree Graduate 26,370 PointsYou only giving a value for the first name. here is a template for your solution, remember you have two conditions
DELETE FROM <table> WHERE <condition> AND <condition>
The table is phone_book while the conditions are the first_name = "Jonathan" and the last_name = "Luna"
DELETE FROM phone_book WHERE first_name = "Jonathan" AND last_name = "Luna"
Cindy Lea
Courses Plus Student 6,497 PointsI would separate your conditons & repeat the AND:
DELETE FROM phone_book WHERE first_name = "Jonathan" AND first_name = "Luna";
If that doesnt work try the EQUALS keyword.
Thomas Nilsen
14,957 PointsI don't think that will work. First_name cannot be Jonathan AND Luna at the same time. Unless I misunderstood the question
Cindy Lea
Courses Plus Student 6,497 PointsThen cant you use the OR instead of AND? You are right abou the AND....
Thomas Nilsen
14,957 PointsDELETE FROM phone_book WHERE first_name in ("Jonathan", "Luna");
is the same as
DELETE FROM phone_book WHERE first_name = "Jonathan" OR first_name = "Luna";