Repository: gocd/gocd
Issue: Loading materials admin page creates syntax error on MySQL 8.0

### Issue Type

- Bug Report

### Summary

the error occurs after start go-server：
```
2023-01-31 11:17:15,621 ERROR [qtp338329632-38] JDBCExceptionReporter:234 - 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 modifications 
) mods JOIN materials m ON mods.materialid=m.id WHERE mo' at line 1
```

### Environment

my system env:
```
Centos 7 - kernel-3.10.0-693
go-server-22.3.0-15301
MySQL 8.0.23
```

db.properties:
```
# /etc/go/db.properties
db.driver=com.mysql.cj.jdbc.Driver
db.url=jdbc:mysql://127.0.0.1:3301/gocd?useUnicode=true&characterEncoding=utf8&useSSL=false
db.user=user_gocd
db.password=xxxxxxxx
db.maxActive=32
db.maxIdle=32
```
### Steps to Reproduce

1. start go-server 
2. click the `AGENTS` OR `MATERIALS` button on the gocd web
3. check the error file /var/log/go-server/go-server.log

### mysql query

```
2023-01-31 11:17:15| cli -> ser |【Query】 SELECT mods.* FROM (   SELECT MAX(id) OVER (PARTITION BY materialid)
 as max_id, *    FROM modifications ) mods JOIN materials m ON mods.materialid=m.id WHERE mods.id=mods.max_id;
2023-01-31 11:17:15| ser -> cli |【Err】 Err code:1064,Err msg:42000You 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 modifications ) 
mods JOIN materials m ON mods.materialid=m.id WHERE mo' at line 1
```

### Possible Fix

read more from [mysql8-select](https://dev.mysql.com/doc/refman/8.0/en/select.html).

Use of an unqualified * with other items in the select list may produce a parse error. For example:
```
SELECT id, * FROM t1
```
to avoid this problem, use a qualified tbl_name.* reference:
```
SELECT id, t1.* FROM t1
```

So we should change the sql:
```
SELECT mods.* FROM (   SELECT MAX(id) OVER (PARTITION BY materialid) as max_id, *    FROM modifications ) 
mods JOIN materials m ON mods.materialid=m.id WHERE mods.id=mods.max_id;

==>

SELECT mods.* FROM (   SELECT MAX(id) OVER (PARTITION BY materialid) as max_id, modifications.*    FROM 
modifications ) mods JOIN materials m ON mods.materialid=m.id WHERE mods.id=mods.max_id;
```

Changed files:
server/src/main/java/com/thoughtworks/go/server/persistence/MaterialRepository.java

diff --git a/server/src/main/java/com/thoughtworks/go/server/persistence/MaterialRepository.java b/server/src/main/java/com/thoughtworks/go/server/persistence/MaterialRepository.java
index 8fe5c7ba3d..162fc4e57c 100644
--- a/server/src/main/java/com/thoughtworks/go/server/persistence/MaterialRepository.java
+++ b/server/src/main/java/com/thoughtworks/go/server/persistence/MaterialRepository.java
@@ -1031,7 +1031,7 @@ public class MaterialRepository extends HibernateDaoSupport {
     public List<Modification> getLatestModificationForEachMaterial() {
         String queryString = "SELECT mods.* " +
                 "FROM (" +
-                "   SELECT MAX(id) OVER (PARTITION BY materialid) as max_id, * " +
+                "   SELECT MAX(id) OVER (PARTITION BY materialid) as max_id, modifications.* " +
                 "   FROM modifications " +
                 ") mods " +
                 "JOIN materials m ON mods.materialid=m.id " +