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
https://forums.phpfreaks.com/topic/35554-order-by-regex/
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
https://forums.phpfreaks.com/topic/35554-order-by-regex/#findComment-168326
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.