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

Development Tools Database Foundations Joining Relational Data Between Tables in SQL Keys and Auto-Incrementing Values

Jeff Styles
Jeff Styles
2,784 Points

Is there a shorter way to write a condition such as "where id = 8 or id = 9 or id = 16"?

Suppose there are many rows to update and "between" isn't an option since they aren't blocked together in numerical order. Is there a way to shorten this, along the lines of: "where id = 8, 9, or 16" ? Thanks.

1 Answer

andren
andren
28,558 Points

The in operator might be what you are looking for. It allows you to specify a comma separated list of values within parenthesis that are checked against the thing you are comparing. For example your query using an in operator would look like this:

where id in (8, 9, 16)
Jeff Styles
Jeff Styles
2,784 Points

Thanks andren. Exactly what I was after.