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 > Need help with using REGEXP in my SELECT statement

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-16-11, 09:41
ral1239 ral1239 is offline
Registered User
 
Join Date: Sep 2011
Posts: 1
Need help with using REGEXP in my SELECT statement

I have a field that contains a list of numbers seperated by commas.

For example, my field would contain something like this:
15,25,16,17,13,16

I only want to search for the very last item in the list. In this case it would be 16. My current SELECT looks like this:

SELECT * FROM `table` where `column` REGEXP ',[[:<:]]16[[:>:]]$'

It returns no records. Whats wrong with my SELECT?

Last edited by ral1239; 09-16-11 at 10:11.
Reply With Quote
  #2 (permalink)  
Old 09-16-11, 11:27
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
use the SUBSTRING_INDEX function for this, with -1 to designate the last item in the list
__________________
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