Example
This input:
AB-100
AB-101
AB-101
O'Brien
AB-104 gives this output with the settings on this page:
('AB-100', 'AB-101', 'O''Brien', 'AB-104') How to build an IN clause from a column
Copy the column in Excel, Sheets or your database client. Paste it into the left box. The settings on this page are already right for SQL: single quotes around text, a comma and a space between values, and parentheses around the list. Duplicates are removed, because a repeated value in an IN list does nothing except make the query longer.
Press Copy and paste the list after IN. Your query looks like this: SELECT * FROM orders WHERE customer_id IN (...).
Numbers, text and apostrophes
Numbers stay bare when Do not quote numbers is on, so 1001 stays 1001. Text gets quotes. A value with leading zeros, such as 007, is treated as text and keeps its quotes, so the zeros survive.
An apostrophe inside a value is doubled. O'Brien becomes 'O''Brien'. This is the standard SQL escape and works in PostgreSQL, MySQL, SQL Server and Oracle. Untick Remove duplicates in Options if you need every row kept.
Limits to know about
- Oracle allows at most 1,000 items in one IN list. Split longer lists into several lists joined with OR.
- SQL Server and PostgreSQL accept very long lists, but a list of tens of thousands of values is slow. A temporary table with a JOIN is faster.
- NULL never matches inside IN. Remove blank lines (on by default) so an empty row does not become an empty string.