How to use the SQL IN Clause Generator
- Paste values, one per line, or separated by commas, semicolons or tabs. A column copied from Excel works as it is.
- Choose Text for codes and names (quoted) or Numbers for IDs (unquoted and checked).
- Optionally enter a column name to get column IN (...), and a chunk size for very long lists.
- Copy the result into your query.
How the list is built
- Cleaning
- Spaces around values and surrounding quotes are removed, and empty values are skipped.
- Quoting
- Text values are wrapped in single quotes, and any single quote inside a value is doubled, so O'Neil becomes 'O''Neil'. This is standard SQL and works in MySQL, SQL Server, Oracle and PostgreSQL.
- Numbers
- In Numbers mode every value must be a number, such as 42, -7 or 3.5; otherwise the tool lists the values that are not.
- Chunks
- With a chunk size, the list is split into several IN lists joined with OR, which keeps each list under database limits.
Examples
These outputs were produced by the same code that runs in the tool above.
SKUs copied from Excel
A pasted column with a duplicate and a value containing a quote.
Values
ZV-1001
ZV-1002
ZV-1001
KID'S-MUG
ZV-1007
SQL
sku IN ('ZV-1001', 'ZV-1002', 'KID''S-MUG', 'ZV-1007')
- Removed 1 duplicate value.
- Single quotes inside values were doubled ('') as SQL requires.
Numeric IDs in chunks
Customer IDs, split into lists of three for the example. For Oracle, use 1000.
Values
1024, 1025, 1031, 1040, 1041, 1077, 1090
SQL
(
customer_id IN (1024, 1025, 1031)
OR customer_id IN (1040, 1041, 1077)
OR customer_id IN (1090)
)
- Split into 3 IN lists of up to 3 values, joined with OR.
Frequently asked questions
Is this safe against SQL injection?
Quotes are escaped correctly, but for queries in application code always use parameters instead of building SQL text. This tool is meant for ad-hoc queries in a database console.
How many values can an IN list have?
Oracle allows 1000 per list. MySQL, PostgreSQL and SQL Server allow far more, but very long lists are slow; a temporary table or join may be better.
Is my data uploaded?
No. The list is built on your device.
Limitations and edge cases
- Commas inside values are treated as separators. Put such values on separate lines and remove the commas, or edit the result.
- Text values are always single-quoted; database-specific types such as dates are not converted.
Read the privacy policy for how the site handles data.