cooldude832 Posted October 20, 2007 Share Posted October 20, 2007 I'm trying to run an ORDER BY addition to my query to do it by last nights, not first name, but I have name as a single field. Any ideas? Link to comment https://forums.phpfreaks.com/topic/74109-solved-ordering-by-last-name-when-the-field-is-name/ Share on other sites More sharing options...
darkfreaks Posted October 20, 2007 Share Posted October 20, 2007 make last and first name a seperate field restructure thedatabase then order by last name Link to comment https://forums.phpfreaks.com/topic/74109-solved-ordering-by-last-name-when-the-field-is-name/#findComment-374180 Share on other sites More sharing options...
pocobueno1388 Posted October 20, 2007 Share Posted October 20, 2007 This is kinda a shot in the dark, but it might work. SELECT SUBSTRING_INDEX(name, ' ', -1) AS last FROM users ORDER BY last Where it says "name", that is where you put the field name where the first and last name is stored. Link to comment https://forums.phpfreaks.com/topic/74109-solved-ordering-by-last-name-when-the-field-is-name/#findComment-374186 Share on other sites More sharing options...
cooldude832 Posted October 20, 2007 Author Share Posted October 20, 2007 seems to work, taking the last word in the Name field mind you the data isn't perfect http://testing.marsvenusinstitute.com/redesign/search.php?search=yes&type=1&location=all&f_type_1=1&f_type_2=1&limit=3&limit=1 Link to comment https://forums.phpfreaks.com/topic/74109-solved-ordering-by-last-name-when-the-field-is-name/#findComment-374189 Share on other sites More sharing options...
pocobueno1388 Posted October 20, 2007 Share Posted October 20, 2007 So it worked? I don't understand what your asking now... Link to comment https://forums.phpfreaks.com/topic/74109-solved-ordering-by-last-name-when-the-field-is-name/#findComment-374192 Share on other sites More sharing options...
cooldude832 Posted October 20, 2007 Author Share Posted October 20, 2007 Well the Name fields I ported off an Old table so some people got their M.D. part in there so it isn't perfect yet, but it is ordering by last word in the Name field so thanks. Link to comment https://forums.phpfreaks.com/topic/74109-solved-ordering-by-last-name-when-the-field-is-name/#findComment-374193 Share on other sites More sharing options...
pocobueno1388 Posted October 20, 2007 Share Posted October 20, 2007 Yeah...I think thats about as good as it's going to get considering the way you set it up. Link to comment https://forums.phpfreaks.com/topic/74109-solved-ordering-by-last-name-when-the-field-is-name/#findComment-374195 Share on other sites More sharing options...
cooldude832 Posted October 20, 2007 Author Share Posted October 20, 2007 People will have to update their data as the last table was horribly built and all the PHD, MD, Mr, Ms stuff was part of the name field that just was disgusting to me so I tried to put it in the new table and it came out ugly. Link to comment https://forums.phpfreaks.com/topic/74109-solved-ordering-by-last-name-when-the-field-is-name/#findComment-374202 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.