I'm working on a message system, and i can't figure this out! The message system is built up something like this,
ID
MESSAGE_ID
MESSAGE
FROM_USER
TO_USER
The message_id can be the same multiple times, thats the ID the from and to users are reading from while checking messages (so they can see all the messages that has been written). But, i need to select all the messages, but i want to skip a row, if the ID has been select before. Is this possible in MySql? or do i need to run a array then remove all duplicated id's?
SELECT `ID`, `MESSAGE_ID`, `MESSAGE`, `FROM_USER`, `TO_USER`
FROM `YourDbTable`
GROUP BY `ID`, `MESSAGE_ID`
Group By may be what you are looking for...
您可以使用group by message_id
Maybe you can try something like this -
SELECT DISTINCT (message_id), message, id,
from_user, to_user
FROM test
GROUP BY message_id
ORDER BY id;
A live demo is given here .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.