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 trialdtap
3,496 PointsSQL Finding Data that Matches Patterns - Challenge 1 of 2
SQL Basics Challenge Task 1 of 2. In the e-commerce database we have a products table. The columns are id, name, description and price. Find all the products where the pattern 't-shirt' can be found anywhere in the product name.
This was my query and it's saying it is incorrect. Anyone with insight so kind enough to help? Thanks folks
SELECT name AS "Product Name", description AS "Product Description" FROM products;
6 Answers
jcorum
71,830 PointsThanks. Yes, they wanted something a bit different:
Task 1
SELECT * FROM products WHERE name LIKE '%t-shirt%'
Task 2
SELECT * FROM users WHERE first_name LIKE 'L%'
jcorum
71,830 PointsWithout a link to the challenge it's a bit of a guess, but try this:
SELECT name AS "Product Name", description AS "Product Description" FROM products WHERE name LIKE '%t-shirt&';
The % is a wild-card, and means any characters at all (even none). So this would get "Large t-shirt", "t-shirt", and "t-shirt with logo".
They may also want you to make it case-insensitive.
dtap
3,496 Points@jcorum - Thanks again!
Sandeep Krishnan
9,730 PointsReally didn't understand the difference between
SELECT * FROM user WHERE first_name LIKE "%L";
AND
SELECT * FROM user WHERE first_name LIKE "L%";
NiKole Maxwell
11,083 Points%L ** - ending with the letter L. In a table of first_names it would return - Hal, Mel, and Saul **L% - beginning with the letter L - the same column would return - Linda, Larry, Lyric. %L% - would return names containing L, for example - Melissa, Alisha, Ally, Bartholomew
Examples of SQL wildcard use from W3schools :
**LIKE Operator Description**
WHERE CustomerName LIKE 'a%' Finds any values that starts with "a"
WHERE CustomerName LIKE '%a' Finds any values that ends with "a"
WHERE CustomerName LIKE '%or%' Finds any values that have "or" in any position
WHERE CustomerName LIKE '_r%' Finds any values that have "r" in the second position
WHERE CustomerName LIKE 'a_%_%' Finds any values that starts with "a" and are at least 3 characters in length
WHERE ContactName LIKE 'a%o' Finds any values that starts with "a" and ends with "o"
dtap
3,496 Points@jcorum - Thanks for your help. I tried that query and I'm still getting the 'bummer' error.
The link to the challenge is here: https://teamtreehouse.com/library/sql-basics/finding-the-data-you-want/finding-data-that-matches-a-pattern-2
BT Murphy
2,404 PointsThanks Nikole. Helped me on the next question after this one.
chase singhofen
3,811 Pointschase singhofen
3,811 Pointsi kept putting the semi colon. very specific and detailed