I want to make a query to get all the data from my table, but without the idPrincipal being repeated, but getting the others idPrincipal
that is, in my table I have the field
id auto increment
idPrincipal
idFinal
sent
msg
the idPrincipal can have id 1 or 2 or 3 infinity of times, but I want to make a query where only show 1 time with the last data they have.
my query that I made was:
SELECT idFinal, sent, msg
DISTINCT idPrincipal from messages
WHERE idFinal = 28
ORDER BY sent DESC
LIMIT 1
but when executing the query it marks me error, I'm using MYSQL
EDITED
My database consists of the following already with real data ...
tabla usuarios
idUsuario,
nombre,
Tabla messages
idMsg,
idEmitter FK usuarios
idReceiver FK usuarios
messages,
nombre,
sent DATE
seenReceiver
I want the messages that have idReceiver
with seenReceiver = 0
but not showing the last message of idReceiver
without repeating it since the way I generated the query generated the records and printed all the that they had seen 0
an example of my result was
idEmitter 1 'mensaje' 'sent' idReceiver 28
idEmitter 1 'mensaje' 'sent' idReceiver 28
idEmitter 1 'mensaje' 'sent' idReceiver 28
idEmitter 3 'mensaje' 'sent' idReceiver 28
idEmitter 3 'mensaje' 'sent' idReceiver 28
idEmitter 3 'mensaje' 'sent' idReceiver 28
idEmitter 5 'mensaje' 'sent' idReceiver 28
idEmitter 5 'mensaje' 'sent' idReceiver 28
idEmitter 5 'mensaje' 'sent' idReceiver 28
I just want the last message sent by the idEmitter to appear
idEmitter 1 'mensaje' 'sent' idReceiver 28
idEmitter 3 'mensaje' 'sent' idReceiver 28
idEmitter 5 'mensaje' 'sent' idReceiver 28
I hope someone can help me