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 trialammarkhan
Front End Web Development Techdegree Student 21,661 PointsWhy use IN, where = make sense?
Just wondering, the proper wording should be
sql "select * from <table> where <col name> = (val1, val2 , val3)"
instead of this,
sql "select * from <table> where <col name> IN (val1, val2 , val3)"
i mean doesn't that make more sense and easy to remember
2 Answers
Adam Brougher
963 PointsSeems like '"IN" means "included".
SELECT * FROM books WHERE date IN (1999, 2005, 1900);
Select all from books where date is included (here); Select all from books where date is not included (here) ;
Steven Parker
231,271 PointsIt doesn't make sense because IN
compares with a list of values, and =
only compares with a single value.
Now if you're wondering why SQL wasn't created that way, perhaps it's because:
- SQL has been around a long time (early 1970's)
- the concept of operator overloading was not a common feature of languages then
- it's a mathematical/business language, not a scientific one
ammarkhan
Front End Web Development Techdegree Student 21,661 PointsHow would one choose 2 values using IN op? Like i want to find our if <val1> or <val2> exists in a column using IN?