Jump to content

ORDER BY & regex


Carterhost

Recommended Posts

I've searched the oracle(Google) and come up with nothing, so I'm trying here:

Can you use regex within a SQL statement?

I have a table, with a column that contains a filename.

Can I order an SQL statement by the extension of the filename (could be .jpg, or .jpeg) without storing the extension as a separate column?

[code]SELECT * FROM files ORDER BY.....?[/code]
Link to comment
Share on other sites

The REGEXP operator in mysql, as best I can tell, will only give you a boolean match similar to a preg_match() call in PHP. You cannot return portions of the string, though. Based on reading extensively through the following two pages of the MySQL manual, I would venture to say that you won't be able to do what you're after in this case. Someone else, please correct me if I'm wrong, though. I've tried to come up with a way myself, to no avail.

http://dev.mysql.com/doc/refman/5.0/en/pattern-matching.html
http://dev.mysql.com/doc/refman/5.0/en/regexp.html
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.