May 24, 2012

Comment: GROUP_CONCAT useful GROUP BY extension

You can chanage separator as follows: mysql> SELECT *, -> GROUP_CONCAT(DISTINCT test_score -> ORDER BY test_score DESC SEPARATOR ‘ |’) -> FROM table_name

Post: GROUP_CONCAT useful GROUP BY extension

… the GROUP BY operation: function GROUP_CONCAT: GROUP_CONCAT(expr) – This function returns a string result with the concatenated non-NULL values from a group. Where… | 6 | | 3 | 7 | +—-+———–+ SELECT id,GROUP_CONCAT(client_id) FROM services WHERE id = 3 GROUP BY id; +—-+————————-+ | id | GROUP_CONCAT(client_id) | +—-+————————-+ | 3 | 5,6…

Post: Eventual Consistency in MySQL

…-join query for each foreign key relationship: mysql> SELECT CONCAT( ‘SELECT ‘, GROUP_CONCAT(DISTINCT CONCAT(K.CONSTRAINT_NAME, ‘.’, P.COLUMN_NAME, ‘ AS `’, P.TABLE….REFERENCED_TABLE_NAME, ‘ ‘, ‘ ON (‘, GROUP_CONCAT(CONCAT(K.CONSTRAINT_NAME, ‘.’, K.COLUMN_NAME) ORDER BY K.ORDINAL_POSITION), ‘) = (‘, GROUP_CONCAT(CONCAT(K.REFERENCED_TABLE_NAME, ‘.’, K…

Comment: GROUP_CONCAT useful GROUP BY extension

… truncated to the maximum length that is given by the group_concat_max_len system variable, which has a default value of… value of group_concat_max_len at runtime is as follows, where val is an unsigned integer: SET [GLOBAL | SESSION] group_concat_max_len = val; Current values in Our server max_allowed_packet = 67107840 group_concat_max_len = 1024 Query…

Comment: Using sets to solve difficult decision problems – the subset sum problem

…: 0 Warnings: 0 mysql> select sum_to_check_for, group_concat(a.val), group_concat(sum_to_check_for), sum(a.val) = sum_to… in(0) group by 1 having sum(a.val) = sum_to_check_for ; +——————+———————+——————————–+———+ | sum_to_check_for | group_concat(a.val) | group_concat(sum_to…

Comment: Using sets to solve difficult decision problems – the subset sum problem

…, here you go: mysql> select sum_to_check_for, group_concat(a.val), group_concat(sum_to_check_for), sum(a.val) = sum_to… in(0) group by 1 having sum(a.val) = sum_to_check_for ; +——————+———————+——————————–+———+ | sum_to_check_for | group_concat(a.val) | group_concat(sum_to…

Post: Advanced index analysis with mk-index-usage

… lots of them: mysql> SELECT CONCAT_WS(‘.’, db, tbl, idx) AS idx, -> GROUP_CONCAT(alt_idx) AS alternatives, -> GROUP_CONCAT(DISTINCT query_id) AS queries, SUM(cnt) AS cnt -> FROM index_alternatives -> GROUP BY db…

Comment: GROUP_CONCAT useful GROUP BY extension

… ! I’ve a little problem using group_concat and user variable. I tried to set a group_concat(id) result into a @var, and…> SELECT @lid := CAST(GROUP_CONCAT(id) AS CHAR) FROM `user` WHERE `nom` in(‘renaud’, ‘julie’, ‘lucy’); +—————————————-+ | @lid := CAST(GROUP_CONCAT(id) AS CHAR) | +—————————————-+ | 4…

Comment: GROUP_CONCAT useful GROUP BY extension

[...] GROUP_CONCAT useful GROUP BY extension: MySQL has useful extension to the GROUP BY operation: function GROUP_CONCAT: GROUP_CONCAT(expr) – This function returns a string result with the concatenated non-NULL values from a group. [...]

Comment: GROUP_CONCAT useful GROUP BY extension

… a bridge table called member_categories. SELECT DISTINCT(md.id),GROUP_CONCAT(categories.category SEPARATOR ‘, ‘) AS category FROM member_directory md LEFT… | CONDOMINIUMS | ==================================================================== If I add any conditions regarding the category, the GROUP_CONCAT starts returning only the category mentioned in the WHERE clause…