Reputation: 251
I have a rows with (firstname, lastname, phone, email
). What I want to make is a query which sort first by concat(firstname, lastname) asc
and the rest rows, where the firstname
and lastname
are null have to come after the sorted by concat(firstname, lastname) asc
and to be sorted depending on phone/email
(if phone
is null sort by email
, if email
is null sort by phone
). Any suggestion can help me?
Upvotes: 0
Views: 64
Reputation: 583
select * from table order by concat(firstname, lastname) asc, (firstname is null and lastname is null) asc, coalesce(phone, email)
Upvotes: 1
Reputation: 1269503
You can put these rules into the order by
. I think these are:
order by (firstname is null and lastname is null) asc,
concat(firstname, lastname),
coalesce(phone, email)
I am not sure if the first condition should be and
or or
.
Upvotes: 3