MorkaLork Development

Interesting stuff I've picked up over the years...

Mysql 7.1: WHERE ... IN

2009-04-16 21:15:21 | 132 views | sql mysql table where in

WHERE ... IN



When searching a table for information you can use the WHERE concept in order to limit the search. If you add 'IN' as well, you can limit the search even more. 'IN' looks at columns and compares them to one OR several conditions. If you only have on condition, IN is exactly the same as just using WHERE.


This will be our table 'person'

|--------------------+--------------------+--------------------|
|Name |Age |Gender |
|____________________+____________________+____________________|
|Bob 34 Male |
|Silvia 67 Female |
|Magnus 24 Male |
|Lisa 32 Female |
+--------------------------------------------------------------+


Syntax:

SELECT column
FROM table_name
WHERE condition
IN ('value', '[italic]value
')[/italic]



SELECT *
FROM person
WHERE Name
IN ('Bob', 'Silvia')


|--------------------+--------------------+--------------------|
|Name |Age |Gender |
|____________________+____________________+____________________|
|Bob 34 Male |
|Silvia 67 Female |
+--------------------------------------------------------------+





Article comments

Feel free to comment this article using a facebook profile.

I'm using facebook accounts for identification since even akismet couldn't handle all the spam I receive every day.