SQL IN Clause Generator
Paste IDs, codes or names and get a SQL IN clause you can drop straight into a query.
Build the IN clause
SQL IN Clause Generator
// Your converted output will appear here.
Apostrophes are escaped by doubling them, which is the standard behaviour every major database accepts.
How to use the SQL IN Clause Generator
Paste your values
One per line, or switch the delimiter if you copied a comma-separated row. Duplicates are removed by default, since they only make the clause longer.
Set the column and operator
Leave the column blank for a bare IN (...) fragment, or name it to get the full WHERE clause. Switch to NOT IN to exclude.
Choose quoted or numeric values
Numbers emits bare numeric literals; Strings quotes everything. Getting this wrong is the usual cause of a type-mismatch error.
SQL IN Clause Generator examples
Numeric IDs with a column name
Input
1001 1002 1003
Output
WHERE id IN (1001, 1002, 1003)
String values containing an apostrophe
Input
O'Brien Smith D'Angelo
Output
WHERE last_name IN ('O''Brien', 'Smith', 'D''Angelo')Standard SQL escapes an apostrophe by doubling it. Backslash escaping is a MySQL-only extension that fails on PostgreSQL, SQL Server, Oracle and SQLite.
Excluding a set
Input
cancelled refunded
Output
WHERE status NOT IN ('cancelled', 'refunded')NOT IN never matches rows where the column is NULL — see the note below.
Working with SQL IN clause generator
Quote your strings, not your numbers
Comparing a numeric column against quoted values forces an implicit cast on some engines and a hard error on others. Worse, on MySQL the cast can silently discard an index and turn a keyed lookup into a full table scan. Match the literal type to the column type.
NOT IN and NULL do not behave as you expect
If the list contains a NULL, NOT IN returns no rows at all — comparing anything to NULL yields unknown, not false. This is the most common bug with generated IN clauses. Use NOT EXISTS, or filter the NULLs out of the list first.
There is a limit to how long this should get
Oracle caps an IN list at 1,000 expressions. SQL Server and PostgreSQL have no hard limit but degrade badly, and a very long clause defeats statement caching because every variation is a new query. Past a few hundred values, load them into a temporary table and join instead.
Popular text conversion tools
Numbers to Array Converter
Convert a list of numbers into an unquoted numeric array, sort it numerically, drop non-numeric values, and read the count, min, max, sum, mean and median.
CSV to Array Converter
Parse real CSV with quoted commas, escaped quotes and headers into arrays of rows or objects, then output JSON, JavaScript, Python or PHP.
List to Array Converter
Paste a bulleted or numbered list and get a clean array. Strips dashes, asterisks, bullets and 1., a) or roman markers so only the values remain.
Line to Array Converter
Convert newline-separated text into an array. Handles CRLF and LF endings, blank lines and the trailing whitespace that copied columns and TXT files carry.
SQL IN Clause Generator FAQs
SQL IN Clause Generator
Paste IDs, codes or names and get a SQL IN clause you can drop straight into a query. Apostrophes are escaped by doubling them, which is the standard behaviour every major database accepts.