If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > values separated by ',' and query values

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-09-09, 08:37
dimis2500 dimis2500 is offline
Registered User
 
Join Date: Jan 2005
Posts: 362
values separated by ',' and query values

I have a table
Quote:
mytable
that have a field
Quote:
myfield
with values separated by ',' .
I want to make a query that return values some spesific values (more than one) of
Quote:
myfield
(example 3,4 or 3 or 3,4,5).
Which is the best way to do that?
Dimis
Reply With Quote
  #2 (permalink)  
Old 01-09-09, 08:44
healdem healdem is online now
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #3 (permalink)  
Old 01-09-09, 10:32
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
Most people try to get their data in to 3NF. Your data is not even in 1NF which is why you're having problems. I'd suggest reading up a bit on normal forms and then just altering your table to hold each value separately ie

Code:
# original string "aaa,bbb,,ddd,eee"

insert mytable ( seq, myfield ) values ( 1, "aaa" );
insert mytable ( seq, myfield ) values ( 2, "bbb" );
insert mytable ( seq, myfield ) values ( 4, "ddd" );
...
Then all you have to write is
Code:
select myfield from mytable where seq in (1,2,3)
Mike
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On