If running the query directly in your database or using mysqli_error(), you would have been presented with:
#1064 - 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 'DISTINCT(operator) as operator, FROM Myfactories
Which would have definitively confirmed what you more-or-less knew.
Then you would naturally look to MYSQL documentation to see what specifications DISTINCT
has by visiting: https://dev.mysql.com/doc/refman/5.7/en/select.html
14.2.9 SELECT Syntax
[ALL | DISTINCT | DISTINCTROW ]
[HIGH_PRIORITY]
[STRAIGHT_JOIN]
[SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT]
[SQL_CACHE | SQL_NO_CACHE] [SQL_CALC_FOUND_ROWS]
select_expr [, select_expr ...]
[FROM table_references
This means that all of those bracketed keywords must come before any column expressions.
Additional tutorial resources that speak specifically about SELECT DISTINCT
on multiple columns include:
Here is one of many, many youtube videos that explain how to use DISTINCT
on multiple columns: https://www.youtube.com/watch?v=-C45IpqUbUA
And if any of those non-StackOverflow resources still didn't do it.
Stackoverflow offers many duplicate questions that are in some ways better than anything else on the net.
Following the correct adjustment of the DISTINCT keyword, you would have been presented with another error:
#1064 - 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 'FROM `MyFactories`
The correction of this typo would be to merely remove the ,
between the factory
column and the FROM
keyword.
As recommended by other pages on SO, you should use the following for your sql statement:
SELECT `date`,`factory`,`operator` FROM `Myfactories` WHERE `factory`='$login_session' AND `Year`='2017' GROUP BY `date`,`factory`,`operator`