Re: sorting data from a field
| From: | Miguel Cruz | Date: | Tue, 26 Mar 2002 21:13:49 +0000 |
| Subject: | Re: sorting data from a field | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-90270@lists.php.net to get a copy of this message | ||
On Sun, 3 Feb 2002, Chuck Barnett wrote:
> I have a db field that holds the first and last name of a person. Is
> there a way to sort by the last name in that field?
>
> The whole reason for this is to populate a select box sorted by last name.
>
> I don't want to go back and create a separate field if I don't have to.
You can do something cheesy like this:
select name from table order by substring(name, locate(' ', name))
but really I'd advise splitting it into separate fields because your
queries will run faster and you'll have more flexibility in the long term.
miguel