Skip to tool
ecech.
💻 Developer & Code

SQL IN Clause Builder That Handles Apostrophes and NULL Properly

Paste a column, get a working IN list — with quotes escaped the standard way and NULL pulled out, because NOT IN with a NULL matches nothing at all.

Values

0

Duplicates removed

0

Needed escaping

0

NULLs found

0

SQL



  
Advertisement

How the calculation works

The query that returns nothing, and does not error IN with a NULL x IN (1, NULL) matches rows where x = 1 The NULL is simply never matched. NOT IN with a NULL x NOT IN (1, NULL) matches NOTHING No error. No rows. Every time. x <> NULL is unknown rather than true, and NOT IN needs every comparison to be true.

How to Use This Tool

Paste a column from a spreadsheet or a query result. You get a working IN clause with the awkward parts handled.

NOT IN with a NULL matches nothing

This is the one worth knowing. x NOT IN (1, 2, NULL) returns zero rows, always, and raises no error.

The reason is three-valued logic. NOT IN expands to x <> 1 AND x <> 2 AND x <> NULL. That last comparison is never true and never false — it is unknown — and an AND containing unknown can never be true. So the whole condition fails for every row.

IN is safe by comparison: the NULL is simply never matched, and the other values work normally. But a single stray NULL in a NOT IN list silently empties your result set, which is why this tool pulls NULLs out and writes OR x IS NULL explicitly instead.

Apostrophes are escaped by doubling

A value like O'Brien ends the string early and breaks the query. The SQL standard escape is to double the apostrophe: 'O''Brien'.

Backslash escaping ('O\'Brien') is a MySQL extension, not standard, and it is off by default in some configurations. Doubling works everywhere, so that is what this produces.

That said — and this matters more than the escaping — if these values come from user input, use parameters instead of building a string. This tool is for pasting a list you already have, not for assembling queries at runtime.

One apostrophe, two outcomes WHERE name IN ('O'Brien') string ends at the second quote → syntax error WHERE name IN ('O''Brien') doubled → one literal apostrophe, works everywhere Backslash escaping is a MySQL extension and is disabled in some modes. Doubling is the standard.
The doubled form is what the SQL standard specifies and every engine accepts.

Length limits

Oracle rejects an IN list of more than 1000 items with ORA-01795. SQL Server and PostgreSQL have no hard limit but slow down badly on very long lists — the planner treats each value separately. Past a few thousand, load the values into a temporary table and join instead. The tool warns when you cross 1000.

Advertisement

Frequently Asked Questions

Why does NOT IN with a NULL return no rows?
Because NOT IN expands to a chain of <> comparisons joined by AND, and comparing anything to NULL gives unknown rather than true or false. An AND chain containing unknown can never be true, so the condition fails for every row. It raises no error, which is what makes it dangerous — the query just quietly returns nothing.
How do I escape an apostrophe in SQL?
Double it: O'Brien becomes 'O''Brien'. That is the SQL standard and every engine accepts it. Backslash escaping is a MySQL extension, is not portable, and is disabled under some SQL modes. If the values come from user input, use parameters rather than escaping at all.
Is there a limit on how many values IN can take?
Oracle caps it at 1000 and raises ORA-01795 beyond that. PostgreSQL and SQL Server have no hard limit but degrade badly on long lists because the planner handles each value separately. Past a few thousand values, insert them into a temporary table and join instead.
Should I use this to build queries in my application?
No. Use parameterised queries for anything involving user input. This tool is for the case where you already have a list — pasted from a spreadsheet or another query — and want to run an ad hoc query by hand.
What happens to blank lines and spacing?
Blank lines are dropped and surrounding whitespace is trimmed, because a value of " Smith" with a leading space almost never matches anything and is almost never intended. Duplicates are removed by default, since IN treats them identically anyway.
Does my data leave the browser?
No. The list is processed in the page. That matters here because pasted column data is often real customer records.

Related tools in Developer & Code

Browse all Developer & Code tools
A handwritten note reading ecech.com resting on the keyboard used to build the site.

Made by one person

ecech. is not a content farm. Every tool here is written and checked by hand, one at a time, by someone who wanted the tool to exist and could not find a version that showed its working.

No accounts and no sign-in, and nothing you type reaches a server — every calculation on this page runs inside your browser. The ads are served by Google and do set their own cookies, which is set out in full on the privacy page. More about the site.