List to SQL

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

0 items / 0 unique
Input Text
0 characters Ctrl+Enter to convert - Drag and drop .txt
Split Input By
Cleaning Options
Output
Output Format
SQL options
Customization
Output 0 unique Output
// Your converted output will appear here.
Paste text and click Convert Text, or use Ctrl+Enter.
Your text stays private. All conversion happens locally in your browser using JavaScript. Nothing is uploaded to any server.

Apostrophes are escaped by doubling them, which is the standard behaviour every major database accepts.

How It Works

How to use the SQL IN Clause Generator

  1. 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.

  2. 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.

  3. 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.

Examples

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.

Notes

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.

FAQ

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.