WmZilla - Webmaster and Marketplace

The Next Generation Webmaster and Trade Forum

Is there an error in this MySQL database query?

KamiOfBarrels

New member

0

0%

Status

Offline

Posts

47

Likes

0

Rep

0

Bits

245

5

Months of Service

0%
Hello friends, when I run the MySQL query that I have, the messages are being sorted from beginning to end instead of from end to beginning. I wonder where the error is in the code. Here is the code:

```
mysql_query("SELECT * FROM (select * from messages ORDER BY messages.message_id DESC) as m2 INNER JOIN chats ON m2.message_chat_id = chats.chat_id WHERE chats.chat_id = 531 GROUP BY chats.chat_id ORDER BY m2.message_id DESC");
```

There are 2 messages in the 'messages' table:
- message_id | sender | recipient | message | chat_id
- 1 | 1 | 2 | first message | 1
- 2 | 1 | 2 | last message | 1

The 'chats' table:
- chat_id | user_1 | user_2
- 1 | 1 | 2

The output is as follows: first message

I asked the friendly hosting team, and they said there is no issue with the system, there might be a problem in the code. However, as they don't have a team specializing in software, they couldn't do anything about it.
 

249

6,622

6,642

Top