Skip to content
Column to Comma,
More free tools

SQL IN list generator: turn a column into an IN clause

Paste the values from your sheet or report. The tool adds single quotes, commas and parentheses, so you can paste the result straight after WHERE column IN.

Direction
Quick:
Options

Options

Your text never leaves your browser. Read how we handle data.

Example

This input:

AB-100
AB-101
AB-101
O'Brien
AB-104

gives this output with the settings on this page:

('AB-100', 'AB-101', 'O''Brien', 'AB-104')

How to build an IN clause from a column

Copy the column in Excel, Sheets or your database client. Paste it into the left box. The settings on this page are already right for SQL: single quotes around text, a comma and a space between values, and parentheses around the list. Duplicates are removed, because a repeated value in an IN list does nothing except make the query longer.

Press Copy and paste the list after IN. Your query looks like this: SELECT * FROM orders WHERE customer_id IN (...).

Numbers, text and apostrophes

Numbers stay bare when Do not quote numbers is on, so 1001 stays 1001. Text gets quotes. A value with leading zeros, such as 007, is treated as text and keeps its quotes, so the zeros survive.

An apostrophe inside a value is doubled. O'Brien becomes 'O''Brien'. This is the standard SQL escape and works in PostgreSQL, MySQL, SQL Server and Oracle. Untick Remove duplicates in Options if you need every row kept.

Limits to know about

  • Oracle allows at most 1,000 items in one IN list. Split longer lists into several lists joined with OR.
  • SQL Server and PostgreSQL accept very long lists, but a list of tens of thousands of values is slow. A temporary table with a JOIN is faster.
  • NULL never matches inside IN. Remove blank lines (on by default) so an empty row does not become an empty string.

Questions about this page

Does this work for NOT IN?

Yes. The list is the same. Write WHERE column NOT IN followed by the list. Remember that NOT IN returns no rows if the list contains NULL.

Can I use double quotes for MySQL?

You can pick double quotes in the Quotes menu. Single quotes are the safer choice, because they are the SQL standard and work in every database.

How do I split a list that is longer than 1,000 items?

Paste the column in chunks of 1,000 rows and create one list per chunk. Join the chunks in the query with OR, for example id IN (...) OR id IN (...).

More conversions

More free tools from Bingemind