About SQL IN Clause Generator
Paste a column of ids from a spreadsheet, a ticket or a log, and get a ready-to-use IN (…) list for a WHERE clause. Numbers stay bare when every value is a number; otherwise every value is quoted with its own quotes escaped, so a name like O’Brien cannot break the query.
Duplicates are removed by default, values can be sorted, and long lists can be split into several IN lists joined with OR, for databases that cap how many values one list may hold.
How it works
- Values are split on new lines, or on commas when everything is on one line; other separators can be chosen. Blank values are skipped and spaces around each value trimmed.
- If every value is a plain number it is written bare. A value with a leading zero, such as 007, makes the whole list quoted, so ids keep their exact form.
- Quotes inside text are doubled; for MySQL, backslashes are doubled too, and SQL Server text gets the N prefix so accents and emoji survive.
- Duplicates are found after quoting, so 1 and +1 count as the same number. With a chunk size, the list is cut into pieces of that many values.
Questions
Why split a long IN list?
Oracle refuses more than 1000 values in one IN list, and very long lists can be slow to parse elsewhere. Set "Values per IN list" to 1000 and name the column; the pieces are joined as (id IN (…) OR id IN (…)).
Is the column name checked or quoted?
No. It is written exactly as you type it, so you can use a table alias such as o.customer_id. Only the values are quoted.
My values already have quotes around them. Will they be doubled?
Not by default. Quotes that wrap a whole value are removed first, and doubled quotes inside it are read as one, so pasting a list that was quoted already gives the same result as pasting the bare values.
How many values can it take?
Up to 5 MB of text, which is several hundred thousand short ids. For a list that long, a temporary table or a join is usually faster than IN.
Everything you enter here is processed in this browser tab. Nothing is uploaded, logged or shared. How privacy works here.