d_barszczak Posted October 10, 2008 Share Posted October 10, 2008 Hi all I have a column `idnumber` that contains data such as SCH-DEP-001 and i want to run a distinct query on this column for everything before the last dash. SCH-DEP- SCH-DEP2- Not all the middle values are 3 digits. Is this possible? Link to comment https://forums.phpfreaks.com/topic/127851-solved-mysql-query-help/ Share on other sites More sharing options...
Barand Posted October 11, 2008 Share Posted October 11, 2008 Is last section always 3 digits? if so: SELECT DISTINCT LEFT(idnumber, LENGTH(idnumber)-4) as id FROM tablename if not (or even if it is) SELECT DISTINCT SUBSTRING_INDEX(idnumber, '-', 2) as id FROM tablename Link to comment https://forums.phpfreaks.com/topic/127851-solved-mysql-query-help/#findComment-662599 Share on other sites More sharing options...
d_barszczak Posted October 13, 2008 Author Share Posted October 13, 2008 Excellent thanks. I wasn't far off but that really helped. Link to comment https://forums.phpfreaks.com/topic/127851-solved-mysql-query-help/#findComment-663845 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.