0

Facing the issue of

incompatible with sql_mode=only_full_group_by;

to resolve the issue, now use ANY_VALUE(<column_name>), It resolves the issue.

But, in some mysql query, We have to use all the columns of db table; where I have used * like :

SELECT * FROM db_table GROUP BY Col_1;

Now How can I apply ANY_VALUE, to the above query.

Please guide.

SELECT ANY_VALUE(*) FROM db_table GROUP BY Col_1;

Throws error.

L. Scott Johnson
  • 4,213
  • 2
  • 17
  • 28
Sachin
  • 111
  • 2
  • 14
  • `any_value()` for all columns ``, like `any_value(column1), any_value(column2), ..., any_value(columnn)`? – sticky bit Jul 22 '19 at 10:32
  • `SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));` more details can be found [here](https://stackoverflow.com/questions/23921117/disable-only-full-group-by) – danish-khan-I Jul 22 '19 at 10:35
  • @danish-khan-I I did the same; but after server restart, ONLY_FULL_GROUP_BY is enabled again. – Sachin Jul 22 '19 at 12:35

2 Answers2

4

If you just a need value you must apply the any_value() function to each column you want select eg:

    SELECT Col_1, any_value(col_2), any_value(col3) 
    FROM db_table 
    GROUP BY Col_1;
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107
  • Is there any method where one by one column is not mentioned? Something like SELECT ANY_VALUE(*). Please confirm. – Sachin Jul 22 '19 at 12:42
  • I confirm .. you can't use any_value(*) .. you must explicitally use each column name you want select .. – ScaisEdge Jul 22 '19 at 12:44
0

Try using any_value:

 SELECT any_value(t.col) 
    FROM table as t
    GROUP BY t.Col_1;
iamdanchiv
  • 4,052
  • 4
  • 37
  • 42
Crysis
  • 418
  • 2
  • 7
  • 28