Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,526 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.