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 SQL Basics Finding the Data You Want Review & Practice with SQL Playgrounds

SQL Playground, Stage 3, "Lovely Review" help

I am trying to retrieve reviews from the user "love" and am having no luck using the following query...

SELECT * FROM reviews WHERE username = "love";

Can someone tell me where I'm going wrong?

7 Answers

(1) You could try a query with wildcards and LIKE:

SELECT * FROM reviews WHERE username LIKE '%love%';
``

This will get all users whose username contains 'love'.

(2) Have you checked the reviews table to see if there are any users whose username is 'love'?

(3) you could test to see if your DBMS is case-sensitive:

```sql
SELECT * FROM reviews WHERE username LIKE '%Love%';
``

Or without the wildcards:

```sql
SELECT * FROM reviews WHERE username = 'Love';
``
Justin Molyneaux
Justin Molyneaux
13,329 Points
SELECT * FROM reviews WHERE username = "__love__";

That is the code that I used and the results came out fine. Note that it has 2 underscores before and after 'love'. In your answers it seems that the word 'love' is being underscored.

Jorgen Rasmussen
Jorgen Rasmussen
3,367 Points

Thanks so much for the tip about 2 underscores, that did it!

Yes, underscores before and after were not showing up, and they would make a big difference. The reason for trying '%love%' was just for testing. You certainly wouldn't want to leave it that way for production use. It was just to see if you had any users with 'love' in any form in their user name.

Lam Cao
Lam Cao
875 Points

SELECT * FROM reviews WHERE username LIKE "%love%";

This should work perfectly as % at the front and back helps you query all the data that contained the word 'love'.

Some DBMSs won't accept double quotes for Strings in WHERE clauses. Try this:

SELECT * FROM reviews WHERE username = 'love';

When you say "no luck" do you mean error messages or no results?

Sorry, to be clear, I get a "Query returned no results" message.

SELECT * FROM reviews WHERE username = 'love';

Tried the above query also, and it yields the same results: "Query returned no results"

I tried using "%love%" However, it occurred to me that when using a more complicated DB that could yield more than I wanted. I assumed I was doing something wrong, but perhaps that's the answer Mr. Calkley (the instructor) was looking for.

To clarify, the username was "love" Not sure if the underscores before and after 'love' are being edited out in my post or whether that is causing some trouble in MySQL queries or not.

Thank guys!