Page 1 of 1

selecting from an array in mysql

Posted: Fri May 05, 2006 7:02 pm
by GeXus
I have the following 1,2,3 in a column called 'x' and I would like to select * where x = 1

How would I do this? do I need IN? I cant seem to get it to work..

Thanks!!

Posted: Fri May 05, 2006 7:24 pm
by feyd

Posted: Sat May 06, 2006 2:38 am
by s.dot
hmm

Code: Select all

SELECT
    *
FROM
    `table`
WHERE
    `x` LIKE '%1%'
:?:

Posted: Sat May 06, 2006 6:15 am
by feyd
scottayy wrote:hmm

Code: Select all

SELECT
    *
FROM
    `table`
WHERE
    `x` LIKE '%1%'
:?:
Assume a field value is 4,10. Is the record returned? ;)

Posted: Sun May 07, 2006 2:26 am
by dibyendrah

Code: Select all

mysql> create database testdb;
Query OK, 1 row affected (0.05 sec)

mysql> use testdb;
Database changed
mysql> create table test (
    -> x varchar(255)
    -> );
Query OK, 0 rows affected (0.03 sec)

mysql> insert into test values('4,10');
Query OK, 1 row affected (0.00 sec)

mysql> insert into test values('5,10');
Query OK, 1 row affected (0.00 sec)

mysql> select * from test;
+------+
| x    |
+------+
| 4,10 |
| 5,10 |
+------+
2 rows in set (0.00 sec)

mysql> select x from test where x like '%4%'
    -> ;
+------+
| x    |
+------+
| 4,10 |
+------+
1 row in set (0.00 sec)


Dibyendra :wink: