Skip to main content

AltF Flow recipe

Convert a list to a SQL IN clause

To query many values at once, wrap each value in single quotes, join them with commas and put the result inside IN ( ). This recipe trims and dedupes the pasted lines first, escapes any apostrophe inside a value by doubling it as SQL requires, then joins everything into one IN clause you can drop into a WHERE condition.

  • Free, no sign-up
  • Runs in your browser
  • Nothing uploaded
  • Share recipes as a link

6 steps · runs in your browser · nothing uploaded

Pipeline

  1. Remove leading and trailing spaces from each line.

    7 → 7 lines
  2. Remove all

    7 → 6 lines (-1)
  3. Keep the first copy of each line and drop repeats.

    6 → 5 lines (-1)
  4. Wrap each line in quotes and escape quotes inside - ready for SQL IN lists, arrays or CSV.

    5 → 5 lines
  5. Separator: ,

    5 → 1 lines (-4)
  6. Prefix: IN (, Suffix: ), Whole text

    1 → 1 lines

7lines6words61chars

1lines6words68chars-6 lines vs input

The 6 steps in this recipe

  1. 1

    Trim every line

    Remove leading and trailing spaces from each line.

  2. 2

    Remove empty lines - Remove all

    Delete blank lines, or squeeze runs of blank lines down to one so paragraphs stay apart.

  3. 3

    Remove duplicate lines

    Keep the first copy of each line and drop repeats.

  4. 4

    Quote each line

    Wrap each line in quotes and escape quotes inside - ready for SQL IN lists, arrays or CSV.

  5. 5

    Join lines - Separator: ,

    Combine all lines into one, with a separator such as ", " or " | ".

  6. 6

    Add prefix / suffix - Prefix: IN (, Suffix: ), Whole text

    Add text before and after every line, or around the whole result.

Change any option in the workspace above, switch a step off to compare, or add your own steps. Save it to reuse it, or share the recipe as a link.

Worked example

Before
SKU-1001
  SKU-1002
SKU-1003 

SKU-1001
O'NEIL-PROMO
SKU-2040
After
IN ('SKU-1001', 'SKU-1002', 'SKU-1003', 'O''NEIL-PROMO', 'SKU-2040')

Why each step is there

  • Trim every line removes spaces copied from spreadsheet cells, which would otherwise end up inside the quotes and match nothing.
  • Remove empty lines and dedupe keep the IN list short and avoid an empty '' value.
  • Quote each line with single quotes doubles any apostrophe, so O'NEIL becomes 'O''NEIL' and the query stays valid.
  • Join lines and the whole-text affix produce IN ('a', 'b') on one line.

Variations

  • For numeric IDs, delete the quote step so the result is IN (1, 2, 3).
  • For a JavaScript or Python array, switch the quote to double and the affix to [ and ].
  • Very long lists can hit database limits on IN size; Keep a range of lines can split them into batches.

List to SQL IN clause: questions and answers

Is this safe against SQL injection?

Doubling apostrophes makes ordinary values valid SQL literals, but for application code always use parameterised queries. This recipe is meant for ad-hoc queries you run yourself.

Can I use double quotes instead?

Yes, but in standard SQL double quotes mean identifiers such as column names, not strings. Use single quotes for values.

Does it work with values copied from Excel or Google Sheets?

Yes. A copied column pastes as one value per line, which is exactly what the recipe expects.

More recipes like this

Every step you can add (41)

Clean up

  • Trim whitespace
  • Trim every line
  • Remove empty lines
  • Collapse repeated spaces
  • Remove line breaks
  • Strip HTML tags
  • Straighten smart quotes
  • Remove accents
  • Remove punctuation
  • Remove emoji
  • Remove non-ASCII characters

Change case

  • Change case
  • Make URL slugs

Lines

  • Sort lines
  • Remove duplicate lines
  • Keep only duplicated lines
  • Compare with another list
  • Count repeated lines
  • Reverse line order
  • Shuffle lines
  • Keep a range of lines
  • Truncate long lines
  • Wrap at a width
  • Split into lines
  • Join lines

Find and filter

  • Find and replace
  • Filter lines
  • Remove words or characters

Extract

  • Extract

Data and formats

  • Format JSON
  • Minify JSON
  • CSV to JSON
  • JSON to CSV
  • Lines to JSON array
  • JSON array to lines

Encode and decode

  • Encode or decode

Build output

  • Add prefix / suffix
  • Quote each line
  • Number lines
  • Apply a line template
  • Add timestamp
What each step does, with its options

AltF Flow runs entirely in your browser. Your text is never sent to AltFTool; saved recipes stay in this browser and shared links carry the steps only.