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

Jan Lundeen
Jan Lundeen
5,886 Points

Only finding one name when I write the SQL query for Challenge Task 1 of 3.

Hi ,

I'm working on Challenge Task 1 of 3 in the SQL Basics class. Here's the question:

In our e-commerce database we have a users table with the columns id, username, password, first_name and last_name. Write a SQL query that retrieves the first and last names only where the username is equal to "wig_lady".

I wrote the following query:

SELECT * FROM users where username = "wig_lady" and first_name IS NOT NULL and last_name IS NOT NULL;

However, they are looking for two records and I only get one record.

Any ideas?

Thanks,

Jan

2 Answers

Jan Lundeen
Jan Lundeen
5,886 Points

Thanks! That worked.

Jan

Umesh Ravji
Umesh Ravji
42,386 Points

Hi Jan, the message isn't telling you there are 2 records, but that there should be 2 columns. I don't know why it only says that there is only 1 when there is 5, but that's beyond me, could be a bug :)

SELECT first_name, last_name
FROM users where username = "wig_lady" and first_name IS NOT NULL and last_name IS NOT NULL;

Once you specify the 2 columns that you want, your SQL works fine, however there's no requirement to check for NULLs, so you can simplify your query too.

SELECT first_name, last_name
FROM users
WHERE username = 'wig_lady';
Jan Lundeen
Jan Lundeen
5,886 Points

Hi Umesh,

That worked. Thanks!

Jan