Today I encountered a little SQL problem I had to solve...so here is the task:
Order the users by their address. Basically this isn't a big thing, but I had all the address parts separatedly in the database. There is a coloumn for the city, street...parts.
Here is the solution:
SELECT *, CONCAT_WS(' ', `users`.`zipcode`, `users`.`city`, `users`.`street`, `users`.`housenumber)` AS address FROM (`users`) ORDER BY `address` asc, `name` ASC
This is not such a great achievement, but it's good for reminding myself about this cool trick.
No comments:
Post a Comment