1

SELECT * FROM raw_stock WHERE date='2002-09-23' group by token ORDER BY time

then I got this:

SELECT list is not in GROUP BY clause and contains non aggregated column 'db.table.table_id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

I saw answer to this here : https://stackoverflow.com/questions/41887460/select-list-is-not-in-group-by-clause-and-contains-nonaggregated-column-inc/41887524#=

but that is if you are not on shared hosting where you have the global right

This question may look like a repetition but it is not, you can Disable ONLY_FULL_GROUP_BY if you have dedicated, VPS servers own by you...but when you host your app on shared hosting the situation is not the same. If you try to Disable ONLY_FULL_GROUP_BY it will tell you, you don't have admin privileges to do so...please correct me if am wrong

  • Write your query properly like you should be doing.. Share table/example data with expected output.. Read https://stackoverflow.com/help/how-to-ask section "Help others reproduce the problem".. it looks like you are trying to unduplicate the data with `GROUP BY` – Raymond Nijland Sep 24 '18 at 12:52
  • Possible duplicate of [Disable ONLY\_FULL\_GROUP\_BY](https://stackoverflow.com/questions/23921117/disable-only-full-group-by) – Madhur Bhaiya Sep 24 '18 at 12:54
  • @MadhurBhaiya it is NOT adviced to disable `sql_mode=ONLY_FULL_GROUP_BY` because you can get matched selected data unrelated to the grouped columns.. – Raymond Nijland Sep 24 '18 at 12:57
  • @RaymondNijland agreed - but sometimes it is helpful, instead of changing a boat-load of queries – Madhur Bhaiya Sep 24 '18 at 12:57
  • 1
    "but sometimes it is helpful, instead of changing a boat-load of queries " that you find unrelated or incorrect data helpful worries me.. @MadhurBhaiya – Raymond Nijland Sep 24 '18 at 12:59

2 Answers2

1

You can change sql_mode at run time. This is how it should work at run time

// connect to mysql and call the first query
mysqli_query("SET SESSION sql_mode = 'TRADITIONAL'");

OR

mysqli_query($conn, "SET SESSION sql_mode = 'TRADITIONAL'");

Also try mysql_query if mysqli_query will not work.

Bhavin Solanki
  • 4,740
  • 3
  • 26
  • 46
  • $con = mysql_connect($server, $user, $password, $database); mysql_query($con, "SET SESSION sql_mode = 'TRADITIONAL'"); mysql_select_db($database) or die(mysql_error()); Thanks for your help but still didn't work – Olugbenga Steve Sep 24 '18 at 13:44
0

you need to select all column by column name and apply them also in group by clause, other that this, this will give error as group by is only use in aggregation, though from your question it is not clear why you need group by in your query

SELECT column1,column2, column3,... FROM raw_stock WHERE date='2002-09-23' group by column1,column2, column3,... ORDER BY time
Fahmi
  • 37,315
  • 5
  • 22
  • 31