Answer the question
In order to leave comments, you need to log in
Duplicate string in Mysql PHP query?
Hello, when trying to make a mysql query, the rows are duplicated in the output, the query itself:
$q = "
SELECT wall.id, wall.owner_id, wall.user_id, wall.text, wall.active, wall.date, wall_photos.photo, wall_audios.audio
FROM wall
LEFT JOIN wall_photos
ON wall.id = wall_photos.wall
AND wall_photos.active = 1
LEFT JOIN wall_audios
ON wall.id = wall_audios.wall
AND wall_audios.active = 1
WHERE owner_id = ?
AND wall.active = 1
ORDER BY wall.date DESC";
$wall = $db->rawQuery($q, [$owner_id]);
Answer the question
In order to leave comments, you need to log in
As an option to scoff around this grouping request:
SELECT
wall.id,
wall.owner_id,
wall.user_id,
wall.text,
wall.active,
wall.date,
GROUP_CONCAT(DISTINCT(wall_photos.photo)),
GROUP_CONCAT(DISTINCT(wall_audios.audio))
FROM wall
LEFT JOIN wall_photos
ON wall.id = wall_photos.wall
AND wall_photos.active = 1
LEFT JOIN wall_audios
ON wall.id = wall_audios.wall
AND wall_audios.active = 1
WHERE owner_id = ?
AND wall.active = 1
GROUP BY wall.id
ORDER BY wall.date DESC
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question