I am trying to make a query in which a value is not repeated since it is repeated several times. In my database, I have these data:
How can I generate a query so that the value of emitter is not repeated? For example, do not repeat the number 2?
so far my query is left as follows:
function obtener_mensajes($conexion, $us){
$statement = $conexion->prepare("SELECT SQL_CALC_FOUND_ROWS * FROM mensajes WHERE receiver = $us AND emitter = emitter AND seen_empresa = 0 LIMIT 1 ");
$statement->execute();
return $statement->fetchAll();
}
Try with DISTINCT
but not result
SOLUTION
Thanks to @ A.Cedano
function obtener_mensajes($conexion, $us){
$statement = $conexion->prepare("SELECT SQL_CALC_FOUND_ROWS *
FROM mensajes WHERE receiver = $us AND seen_empresa =
0 GROUP BY emitter ORDER BY id ASC ");
$statement->execute();
return $statement->fetchAll();
}
in this way it stops repeating emitter