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 trial

Databases

Donnie Driskell
Donnie Driskell
2,243 Points

Filtering information (SOLVED)

We're still using the phone_book, with the columns id, first_name, last_name and phone.

Imagine we're implementing the autocomplete feature for a search facility on the phone where a user can start typing a last name and suggestions will appear. Write a query to retrieve all values from the last name column where the last name value is present. Only retrieve the last_name column.

OK ! I finally got the answer after a lot of tries and re watching video -- tricky. SELECT last_name FROM phone_book WHERE last_name IS NOT NULL;

I can not seem to get the string correct to answer this correctly. I would appreciate help - thank you. I have been using the IN keyword. Here are some examples I tried.

  1. SELECT * FROM phone_book WHERE last_name IN phone_book;
  2. SELECT id, first_name, last_name, phone FROM phone_book WHERE last_name IN phone;
  3. SELECT id, first_name, last_name, phone FROM phone_book WHERE phone IN last_name;
  4. SELECT id, first_name, last_name, phone FROM phone_book WHERE last_name IN phone_book;
  5. SELECT last_name FROM phone_book WHERE last_name IN phone_book;
  6. SELECT last_name FROM phone_book WHERE phone IN phone_book;

I am embarrassed of posting my errors, but I need to learn what I am doing wrong. Thanks Donnie https://teamtreehouse.com/library/sql-basics/finding-the-data-you-want/filtering-out-or-finding-missing-information-2

He is asking you to add the whole details of the people who doesn't have phone numbers in order to ask those people for their phone number.

You can find the missing phone numbers by doing the following:

SELECT * FROM phone_book where phone IS NULL;

The only mistake that you are doing is that you are writting 'NOT NULL' instead of 'NULL'

NULL means that column is empty and doesn't contain any data in it NOT NULL means that the column is not empty and contain data inside of it

1 Answer

J.D. Sandifer
J.D. Sandifer
18,813 Points

Donnie answered his own question, but forgot to use the answer section so here it is again:

OK ! I finally got the answer after a lot of tries and re watching video -- tricky. SELECT last_name FROM phone_book WHERE last_name IS NOT NULL;

there is error : Was expecting 2 columns, not 1.