Copy link to clipboard
Copied
Out of curiosity (I dont know much about sql queries) why would the query below flag an error and not work if 'FROM' was to followed directly on after the first instance of Max(departDate) ???? (difficult to see below but there is a break directly before FROM so it goes onto its own line.
$excursionMonth = $conn->query("SELECT DISTINCT departMonth, excursionYear, MAX(departDate)
FROM excursions GROUP BY departMonth, excursionYear ORDER BY MAX(departDate) ASC") or die($conn->error);
If FROM is not started on its own line the browser error is:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'excursions GROUP BY departMonth, excursionYear ORDER BY MAX(de' at line 1
OR error in sql console:
2 errors were found during analysis.
If FROM is on its own line there are no errors and the query works.
So from that can I assume that some sql statements need to go on their own line?
OK - I think there must have been some invisible shite character gotten into the string of code somehow/somewhere corrupting the statement. When I retyped the complete query from scratch all in one line it worked perfectly!!!
I know its probably better to format the code into several lines anyway but it looks neater and more compact in one line and I work faster that way.
I understand your point,
so let stuff as they are... at least you should be able to reduce it some
from
SELECT DISTINCT departMonth, excursionYear, MAX(departDate) FROM excursions GROUP BY departMonth, excursionYear ORDER BY MAX(departDate) ASC
going to
SELECT departMonth, excursionYear FROM excursions GROUP BY departMonth, excursionYear ORDER BY departDate ASC;
Copy link to clipboard
Copied
Heres one link, below. Its not the one that I sourced the information from though but there plenty about it if you Google:
https://www.percona.com/blog/2019/05/13/solve-query-failures-regarding-only_full_group_by-sql-mode/
Copy link to clipboard
Copied
OK well I think by running SET SQL_MODE = ''; in the phpMyAdmin sql console that has gotten rid of what it was previously set to. That I dont know because when I look now of course it is set to nothing.
Now yours and my sql queries BOTH work BUT now I don't know if setting the SQL_MODE to nothing was a wise thing to do......humm.
Anyway if I have the same issue remotely I can either set the SQL_MODE = '' or use my query.
At least now I know what to look for and what the cause might be. I wish these people would not bugger about changing things so much from version to version which causes breakages and makes our job a lot more difficult.
Even the query that I had been using for years and apparently should not work does work now that the mode has been set to '' It's obviously ALL about what the sql mode is set to as to whether a query will run:
SELECT DISTINCT departMonth, excursionYear FROM excursions ORDER BY departDate
I havent even SELECTED departDate in the query above yet it runs!!!!