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 trialTadjiev Codes
9,626 PointsSQL
Dear Folks, I just wanted to ask regarding SQL statement, The question: Without using the logical operator OR, list all vendors from Ontario, Alberta, and BC who are not in the 416 and 780 area codes. Also, sort this list by city within the province:
The phone number is in the format (416)555-6453
I tried writing a statement in different ways.
SELECT * FROM vendors WHERE province IN ('ON','AB','BC') AND phonenumber NOT IN ('416' ,'780') ORDER BY province, city;
SELECT * FROM vendors WHERE province IN ('ON','AB','BC') AND (phonenumber NOT LIKE '416%') ORDER BY province, city;
// Tried using NOT BETWEEN 416 AND 780 AS well // Though 416 and 780 part is not working I need to exclude the vendors whose phone number starts with 416 or 780
Thanks in advance)))
2 Answers
Steven Parker
231,198 PointsNote that neither of these checks would match a number like the sample "(416)555-6453":
-
IN ('416', '780')
would only match those two 3-digit values -
LIKE '416%'
would not match anything beginning with '('
If you need more info, please provide a link to the course page you are working with.
Tadjiev Codes
9,626 PointsSELECT *
FROM Vendors
WHERE Province IN ('ON', 'AB', 'BC') AND phonenumber NOT LIKE '(780)%' AND phonenumber NOT LIKE '(416)%'
ORDER BY province, city;
Thanks, Mr.Steven) This seems to work actually when I used the parentheses and WildCard character outside '(780)%'