SELECT * FROM (
SELECT * FROM doctrine_migration_versions ORDER BY execution_time ASC LIMIT 3
) r ORDER BY r.execution_time DESC;
SELECT *, 'post_table' FROM post WHERE parent = 28
UNION
SELECT *, 'razdel_table' FROM razdel WHERE parent = 28
... AND (table1.field1 = table2.field1 OR table1.field1 IS NULL AND table2.field1 IS NULL) AND ...
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