MySQL: Sort GROUP_CONCAT values

In short: Is there any way to sort the values in a GROUP_CONCAT statement? Query: GROUP_CONCAT((SELECT GROUP_CONCAT(parent.name SEPARATOR ” &raquo; “) FROM test_competence AS node, test_competence AS parent WHERE node.lft BETWEEN parent.lft AND parent.rgt AND node.id = l.competence AND parent.id != 1 ORDER BY parent.lft) SEPARATOR “<br />\n”) AS competences I get this row: Crafts … Read more

What is the purpose of Order By 1 in SQL select statement?

I’m reading through some old code at work, and have noticed that there are several views with an order by 1 clause. What does this accomplish? Example: Create view v_payment_summary AS SELECT A.PAYMENT_DATE, (SELECT SUM(paymentamount) FROM payment B WHERE PAYMENT_DATE = B.PAYMENT_DATE and SOME CONDITION) AS SUM_X, (SELECT SUM(paymentamount) FROM payment B WHERE PAYMENT_DATE = … Read more

how to customize `show processlist` in mysql?

I want to order by Time,but seems no way to do that ? mysql> show processlist; +——–+————-+——————–+——+———+——–+———————————-+——————————————————————————————————+ | Id | User | Host | db | Command | Time | State | Info | +——–+————-+——————–+——+———+——–+———————————-+——————————————————————————————————+ | 1 | system user | | NULL | Connect | 226953 | Waiting for master to send event | … Read more

PostgreSQL DISTINCT ON with different ORDER BY

I want to run this query: SELECT DISTINCT ON (address_id) purchases.address_id, purchases.* FROM purchases WHERE purchases.product_id = 1 ORDER BY purchases.purchased_at DESC But I get this error: PG::Error: ERROR: SELECT DISTINCT ON expressions must match initial ORDER BY expressions Adding address_id as first ORDER BY expression silences the error, but I really don’t want to … Read more