Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select all distinct filename extensions from table of filenames?

Tags:

mysql

I have a table of ~20k filenames. How do I select a list of the distinct extensions? A filename extension can be considered the case insensitive string after the last .

like image 643
user784637 Avatar asked Jun 19 '12 01:06

user784637


1 Answers

You can use substring_index:

SELECT DISTINCT substring_index(column_containing_file_names,'.',-1) FROM table

-1 means it will start searching for the '.' from the right side.

like image 102
bnvdarklord Avatar answered Oct 19 '22 21:10

bnvdarklord