mysql - How to ORDER BY a person's first_name but ALSO insert nicknames ASC -
here example data:
nickname first_name last_name ======= ======= ======= charlie smith beta jones alpha chris anderson delta nick andrews
this result want (first letters a, b, c, d)
- "alpha" chris anderson
- beta jones
- charlie smith
- "delta" nick andrews
my problem when run usual order nickname asc, first_name asc
(b, c, a, d):
- beta jones
- charlie smith
- "alpha" chris anderson
- "delta" nick andrews
any ideas?
you want coalesce()
:
order coalesce(nickname, first_name)
this assumes blank values null
. if empty strings, then:
order coalesce(nullif(nickname, ''), first_name)
Comments
Post a Comment