I have upgraded my MySQL server and now I have a problem with group by
select * from tickets WHERE `status` = 0 group by `tnumber` ORDER BY `created_at` DESC
error is:
SELECT list is not in GROUP BY clause and contains nonaggregated column
Updated: my table content is:
<!DOCTYPE html>
<html>
<head>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
</head>
<body>
<h2>id</h2>
<table>
<tr>
<th>id</th>
<th>tnumber</th>
<th>title</th>
<th>status</th>
</tr>
<tr>
<td>1</td>
<td>5c63e00a072c1</td>
<td>1111</td>
<td>1</td>
</tr>
<tr>
<td>2</td>
<td>5c63e00a072c1</td>
<td>1111</td>
<td>1</td>
</tr>
<tr>
<td>3</td>
<td>5c63e00a072c1</td>
<td>1111</td>
<td>1</td>
</tr>
<tr>
<td>4</td>
<td>5c63e00a072c1</td>
<td>1111</td>
<td>0</td>
</tr>
<tr>
<td>5</td>
<td>5c63ead5bd530</td>
<td>2222</td>
<td>1</td>
</tr>
<tr>
<td>6</td>
<td>5c63ead5bd530</td>
<td>2222</td>
<td>1</td>
</tr>
</table>
<br/>
I want to have following output:
<br/>
<br/>
<br/>
<table>
<tr>
<th>id</th>
<th>tnumber</th>
<th>title</th>
<th>status</th>
</tr>
<tr>
<td>1</td>
<td>5c63e00a072c1</td>
<td>1111</td>
<td>0</td>
</tr>
<tr>
<td>2</td>
<td>5c63ead5bd530</td>
<td>222</td>
<td>1</td>
</tr>
</table>
</body>
</html>
My code is :
SELECT * FROM tickets
WHERE `tnumber` IN (
SELECT tnumber FROM tickets GROUP BY tnumber
)
but group by in second Select in where, doesn't have any affecs!!! How to do it in a propper way?
The GROUP BY statement is often used with aggregate functions (COUNT, MAX, MIN, SUM, AVG) to group the result-set by one or more columns.