SQLite Forum

Filter one column for multiple values
Login
This will, of course, require a full scan so it will work just fine if the table `ctl` has 10 rows (such as when testing) but will not be performant if the table `ctl` has a billion rows -- depending on if other conditions in the where clause can cull the candidates which need testing to a relatively small number before this condition is tested.

If you need to do this regularly you might create an an index as follows to address this:

```
create index ctl_idx on ctl (substr(partner_sku, 1, instr(partner_sku, '-')-1));
```

after which:

```
select * from ctl where substr(partner_sku, 1, instr(partner_sku, '-')-1) in ('A1012', 'A207', 'KH108');
```

will use the index to find just the rows you are interested in.


Alternatively, you could add a virtual column to the table containing the prefix and index that, and use the virtual column in the where clause instead:

```
alter table ctl add column partner_sku_prefix text as (substr(partner_sku, 1, instr(partner_sku, '-')-1));
create index ctl_idx on ctl(partner_sku_prefix);
```
and then

```
select * from ctl where partner_sku_prefix in ('A1012', 'A207', 'KH108');
```

which will do the same thing, but you will not need to keep typing the long expression whenever you need to access the partner_sku_prefix.