How to Convert an Excel Column to a SQL IN Clause
Convert an Excel or Google Sheets column into a SQL IN (…) list. Handle quotes, duplicates, numeric IDs, text values, Oracle 1000-item limits, and PostgreSQL arrays.
On this page
A common SQL task starts outside the database:
You have a column of IDs, email addresses, SKUs, or account numbers in Excel or Google Sheets, and you need to use those values in a query such as:
SELECT *
FROM customers
WHERE customer_id IN (101, 205, 309);
You can build the list manually, use a spreadsheet formula, or paste the column into the free SQL IN Clause Generator.
Convert an Excel column to SQL IN(…)
Suppose your spreadsheet contains:
101
205
309
205
412
Copy the cells and paste them into the SQL IN Clause Generator.
For numeric values, the generated condition can be:
WHERE customer_id IN (101, 205, 309, 412)
The duplicate 205 can be removed automatically.
This is usually faster and less error-prone than manually inserting commas and parentheses.
Convert text values
Text values must be quoted correctly.
For example:
pending
approved
cancelled
becomes:
WHERE status IN ('pending', 'approved', 'cancelled')
Select String / Text in the generator so values are wrapped in single quotes.
Escape apostrophes correctly
Apostrophes inside SQL string literals must be escaped.
This Excel column:
O'Connor
D'Angelo
Smith
cannot safely become:
IN ('O'Connor', 'D'Angelo', 'Smith')
because the inner apostrophes terminate the string literals.
Correct SQL doubles the quote:
IN ('O''Connor', 'D''Angelo', 'Smith')
The generator handles this automatically in string mode.
Remove duplicates
Lists copied from business spreadsheets often contain duplicates.
For an IN predicate, repeating the same literal usually adds no value:
WHERE id IN (10, 20, 20, 30, 30, 30)
can be simplified to:
WHERE id IN (10, 20, 30)
Enable Deduplicate to keep only unique values.
Generate NOT IN
The same list can be used for exclusions:
WHERE status NOT IN ('cancelled', 'archived')
Choose the NOT IN output format in the generator.
Remember that SQL NOT IN has special behavior when the list or subquery contains NULL. If nulls are possible, check the target database’s semantics before relying on the predicate.
Oracle and more than 1,000 expressions
Large spreadsheets can exceed Oracle’s expression limit for a single IN list.
Instead of one huge list, split it into chunks:
WHERE (
customer_id IN (/* first group */)
OR customer_id IN (/* second group */)
)
The SQL IN Generator includes a Chunk by 1,000 option for this use case.
For NOT IN, chunks must be joined with AND rather than OR to preserve the intended logic.
PostgreSQL array alternative
PostgreSQL applications can also compare against arrays:
WHERE customer_id = ANY(ARRAY[101, 205, 309])
The generator includes a PostgreSQL array output mode.
This can be useful when application code already passes values as an array parameter instead of constructing a dynamic SQL list.
Parameter placeholders
If you are writing application code, embedding user-provided values directly into SQL text is usually the wrong approach.
Use parameters instead.
For example:
WHERE customer_id IN (?, ?, ?, ?)
The generator can produce placeholder-style output, but your database library is still responsible for binding values safely.
Do not concatenate untrusted input directly into production SQL.
When an IN list becomes too large
An IN clause is convenient for dozens or hundreds of values, but very large lists become difficult to maintain and can create large SQL statements.
If you have tens of thousands of values, consider loading them into a temporary or staging table and joining instead.
If the values already exist in a CSV file, the CSV to SQL Converter can generate a staging table and batched inserts.
Then query it with a join:
SELECT c.*
FROM customers c
JOIN selected_customer_ids s
ON s.customer_id = c.customer_id;
MySQL and PostgreSQL IN operator references
For operator semantics and NULL behavior, see:
For the practical spreadsheet-to-query workflow, open the SQL IN Clause Generator.