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 trialArun Kanagala
iOS Development Techdegree Student 617 Pointsquery help
Inside the products table we have the columns of id, name, description and price.
Without using the OR keyword, find all products with the price of 7.99, 9.99 or 11.99.
Query:
SELECT id, name, description, price FROM products WHERE price in (7.99, 9.99, 11.99);
please let me know whats incorrect
3 Answers
Maximillian Fox
Courses Plus Student 9,236 PointsHey there,
I have edited this answer according to pointers by Steven Parker below. You should vote his answer as the best one, but I think it prudent to correct my mistakes. Thank you Steven for the pointers.
I will remove the space between IN and the opening bracket, you don't have to do this, it's just how I've seen it shown in MySQL.
SELECT id, name, description, price FROM products WHERE price in(7.99, 9.99, 11.99);
If you are selecting all the columns, you don't need to list them all out. The following statement is equivalent to the above one :)
SELECT * FROM products WHERE `price` in(7.99, 9.99, 11.99);
You can use the * as a 'select all' syntax in this case.
If the question only wants the product name, try this:
SELECT name FROM products WHERE price in(7.99, 9.99, 11.99);
Steven Parker
231,261 PointsActually, the only thing that needed to be changed to pass the challenge was to use (*) for the select list. The rest of it was just fine.
SELECT * FROM products WHERE price in (7.99, 9.99, 11.99);
Also:
- leaving off the semicolon is a bad habit. It may be optional in Sqlite, but some other databases require it.
- IN is not a function, it is a comparison operator
- operators are NEVER case sensitive
- quoting identifiers is almost never necessary, and can cause complications (like unintended case sensitivity)
Maximillian Fox
Courses Plus Student 9,236 PointsUpvoted - learn something new every day! I use MySQL a ton which by default doesn't require some of the semicolons, but I now know to add it by default. Thanks for correcting me. OP should select this as best answer.
Zachary Wheeler
1,157 Pointswhere do i insert the != after WHERE?