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 > Can someone help in this?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-01-11, 02:59
mohansinfh mohansinfh is offline
Registered User
 
Join Date: Nov 2010
Posts: 2
Can someone help in this?

I am having records in a field (field_id) of a table (in mysql database), which is having ID stored per line, for example

1
2
3
10
11
13



above is one record, and I have many records similar to that.

and, when I am writing the query SELECT * FROM $table_name where field_id like '%1%'

then the rows having the results like
10
11
13


are also returned. I am upset. How to overcome this problem?

I found one fix to this, but it fails in most of the conditions, this is -

SELECT * FROM `$table_name` WHERE field_id like '%\n1%' OR '%1\n%'

This fails, when the (field_id) have only one record, for example, '1'. I want to catch everything, where line equals to 1, whether single line in the record, or many.

I am going mad for this.

Can someone provide me any way? Thanks.
Reply With Quote
  #2 (permalink)  
Old 04-01-11, 05:16
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
Quote:
Originally Posted by mohansinfh View Post
I am upset. How to overcome this problem?
Upset: Have you tried Xanax?
SQL: can you reword this question to make it easier to understand?
__________________
Mike
Reply With Quote
  #3 (permalink)  
Old 04-01-11, 05:44
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
my sincere advice: normalize your data

otherwise your query will always perform a table scan, i.e. it will start off really slow and get slower and slower the more rows you have

but if you insist on keeping the current design, try this --
Code:
WHERE CONCAT(',',REPLACE(REPLACE(field_id,'\r',''),'\n',','),',') LIKE '%,1,%'
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
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