homepage Welcome to WebmasterWorld Guest from 54.242.126.126
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

    
Explode MySql Records
Gian04

5+ Year Member



 
Msg#: 4032193 posted 1:52 pm on Nov 26, 2009 (gmt 0)

Is there a way to explode mySQL records / values while searching for records

example : SELECT * FROM tablename WHERE field = 'explode("-",field')...

I cant use the operator LIKE because the field can have records like

12-10-1
97-100-4
86-896-10-67-4
7-5

If I want to search for records with 10, it should only return the 1st and 3rd record.

 

rocknbil

WebmasterWorld Senior Member rocknbil us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4032193 posted 4:19 pm on Nov 26, 2009 (gmt 0)

Not that I know of. Can you use regular expressions? You should be able to substitute like for regexp though . . .

$some_var = '10';

select * from tablename where field regexp '.*$some_var.*';

or

select * from tablename where field regexp '.*\-$some_var\-.*';

Might have to do an "or" if it's potentially a leading or trailing:

select * from tablename where field regexp '.*\-$some_var\-.*' or field regexp '$some_var\-.*' or field regexp '.*\-$some_var';

you can also try instr() [dev.mysql.com]:

select * from tablename where instr(field,'$some_var');

Though that will match on 100 . . .

jmccormac

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



 
Msg#: 4032193 posted 7:59 am on Dec 1, 2009 (gmt 0)

RLIKE. It is LIKE but with regexp.

Regards...jmcc

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved