# Solved: mysql select in



## snorkytheweasel (May 3, 2006)

Consider these statements:

```
select * from [I]sometable[/I] where [I]thiscolumn[/I] in(1,2,3);
```
That returns all rows where column id is one of those three values.


```
select * from [I]sometable[/I] where [I]thiscolumn[/I] like("a%");
```
That returns all rows where the first character of a column thiscolumn is 'a';

What I'm trying to do is to combine the two concepts as in something like


```
select * from [I]sometable[/I] where  [I]thiscolumn[/I] in('like("b%")','like("c%")');
```
That returns all rows where the first character of a column thiscolumn is 'a' or 'b';

That syntax is wrong.

I've tried setting variables

```
set @var1: 'like="b%"';
set @var2: 'like="c%"';
```
Again, bad syntax.

I could use ...

```
[I]thiscolumn[/I] like("b%") or [I]thiscolumn[/I] like("c%") or [I]thiscolumn[/I] like("da%")
```
 ..._ ad_ nausem. But if there are many values in the set, it becoms quite clunky.

I've tried the mysql manual and google. The problem with those is trying to figure out how to ask the question. A forum like this gives me the ability to (hopefully)seek, explain, and find the solution.

In this case I don't have the luxury of using php; I have to do it within mysql.

Ideas?


----------



## snorkytheweasel (May 3, 2006)

And the answer is .... 
This won't work.
But regular expressions in the SQL statements will work.


----------

