selecting from an array in mysql

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

selecting from an array in mysql

Post 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!!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

hmm

Code: Select all

SELECT
    *
FROM
    `table`
WHERE
    `x` LIKE '%1%'
:?:
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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? ;)
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post 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:
Post Reply