SQL IN Clause Generator
Turn a pasted list of IDs or values into a SQL IN clause, quoted and de-duplicated, ready for a WHERE condition.
Was this tool helpful?
Thanks for the feedback!
This tool turns a pasted list of IDs or values into a SQL IN (...) clause, quoted, escaped and with duplicates removed, ready to drop into a WHERE condition. It saves analysts and developers from adding commas and quotes by hand when someone sends a column of order numbers from Excel. It can also split long lists into groups of 1,000 for Oracle.
The fields
| Field | Choices and effect |
|---|---|
| Column name, optional | If filled, the output starts WHERE column IN (. If blank, it is just IN (...). |
| Quotes | Automatic (numbers bare, text quoted), Always quote, or Never quote |
| Duplicates | Remove duplicates, or Keep duplicates |
| More than 1,000 values | Keep one IN list, or Split into OR groups of 1,000 (Oracle) |
How the list is read
Values are split on new lines, commas and tabs. Spaces do not split, so "New Delhi" stays one value. Each value is trimmed, one pair of matching quotes around it is removed, and empty entries are dropped. Duplicate removal keeps the first copy and is case-sensitive, so Pune and pune are both kept.
With Automatic quotes, the tool checks whether every value is a plain number (digits, an optional minus sign and an optional decimal part). If they all are, it leaves them bare. If even one is not, it quotes all of them. Inside quoted values, every apostrophe is doubled, which is how SQL escapes it. The stats show the number of values, how many duplicates were removed and whether quoting was used.
Worked examples
A list of five customer IDs with one repeat, column customer_id:
1001
1002
1003
1002
1004
WHERE customer_id IN (1001, 1002, 1003, 1004)
The stats show 4 values and 1 duplicate removed. A list of cities with column city, where one value is already in double quotes and one contains an apostrophe:
Pune
Mumbai
O'Neil
"Delhi"
Pune
WHERE city IN ('Pune', 'Mumbai', 'O''Neil', 'Delhi')
Leading zeros, NULL and other traps
- Codes with leading zeros: Automatic mode sees
007, 008, 009as numbers and writesIN (007, 008, 009), which the database reads as 7, 8 and 9. If the column is text, choose Always quote to getIN ('007', '008', '009'). - In a mixed list,
101,102andABC-7are all quoted in Automatic mode, because one value is not a number. Never quote writes them bare, so use it only when every value is a number or an expression. INnever matches rows where the column is NULL, and aNOT INlist containing NULL returns no rows at all. Handle NULLs with a separateIS NULLcondition.- A comma inside a value always splits it in two, so add any value such as "Sharma, R." to the clause by hand.
An empty box gives "Paste a list of values, one per line or separated by commas."
Oracle's 1,000-item limit
Oracle Database rejects an IN list with more than 1,000 expressions, with the error ORA-01795: maximum number of expressions in a list is 1000. Choose "Split into OR groups of 1,000 (Oracle)" and any list longer than 1,000 is wrapped like this:
WHERE (order_id IN (100001, 100002, ...)
OR order_id IN (101001, 101002, ...)
OR order_id IN (102001, 102002, ...))
That is what the tool produces for 2,500 order IDs: three groups of 1,000, 1,000 and 500. If you leave the column name blank, it uses the placeholder column_name, which you must replace. Lists of 1,000 or fewer are never split. Other databases have no fixed limit this small, but very long lists make queries slow and hard to read, so for many thousands of values a temporary table and a join is usually better.
To clean a messy list first, the duplicate line remover helps. To tidy the full query, use the SQL formatter.
Frequently asked questions
How do I turn an Excel column into a SQL IN clause?
What is the maximum number of values in a SQL IN clause?
How do I escape an apostrophe in a SQL IN list?
Should numbers be quoted in an IN clause?
Does the tool remove duplicate values?
Can my values contain spaces?
Related guides
- Free Developer Tools That Replace a Dozen Browser Tabs Free developer tools grouped by job: format, convert, encode, generate and test. What each one does, which run on the server, and the limits to know f...
- How to Beautify CSS, HTML and XML (Online, VS Code, Prettier) Beautifying adds line breaks and indentation so minified CSS, HTML or XML is readable again. How the free formatters work, their limits, and VS Code a...
- How to Format JSON: Pretty-Print, Validate and Read Errors Paste JSON into a formatter to indent it and catch errors. The exact syntax rules, how to read an error position, and how to do it in VS Code, Python...