SQLite Forum

Filter one column for multiple values
Login
>I am very new to SQLite and still learning.

That should be fun. I will presume you're new to SQL as well.

> I have imported a csv file called 'CATALOGUE.csv' to a table called 'ctl' and running a query to filter the column 'partner_sku' for strings of certain pattern as below;

I almost cut that table source as not germane.

> <code>SELECT partner_sku FROM ctl WHERE partner_sku LIKE 'A1012%' OR partner_sku LIKE 'A207%' OR partner_sku LIKE 'KH108%';
</code>For few number of criteria in this query is alright, but as number grows it looks mess to handle.


Your instincts are right on this. If that WHERE clause represents just a happenstance set of criteria, then a somewhat repetitive condition is harmless. But if those LIKE terms represent a set derived logically from other data, there should probably be another table (or more) so that you can express your selection as a join. (See https://sqlite.org/optoverview.html#joins .)

I also wonder if your "partner_sku" is not a composition. Seeing its values' leading letters makes me suspect they encode information that should occupy more than one column in a table. That refinement might reduce the need for extensive WHERE clauses. If this makes no sense yet, you probably should study "database normalization". It's a big subject, but important for serious database work. Even a short tutorial on it could benefit your schema design.

> I read about WHERE with IN CLAUSE but don't know how to incorporate that here. Need your kind help.

If you truly need LIKE expressions, (after such normalization as you see fit to perform), they are not going to go into an IN clause in a simple way.