SELECT
user_images.id AS image_id, user_images.user_id AS user_id,
user_images.create_date AS image_create_date, user_images.name AS image_name,
user_images.title AS image_title, user_images.descr AS image_descr,
user_images.views AS image_views, user_images.plus AS image_plus,
user_images.minus AS image_minus,
bpl_users.first_name AS user_first_name, bpl_users.last_name AS user_last_name,
bpl_users.photo AS user_photo,
(SELECT COUNT(*) FROM `comments` WHERE `image_id`=`user_images`.`id` ) AS quantity_comments
FROM `user_images` INNER JOIN `bpl_users`
ON `user_images`.`user_id`=`bpl_users`.`id`
ORDER BY `user_images`.`create_date` DESC LIMIT 9
SELECT id, user_id, read_state, text, date, out
FROM Table AS T1
WHERE date = ( SELECT MAX(date) FROM Table Where user_id=T1.user_id )
SELECT T1.id, T1.user_id, T1.text, T1.date
FROM Table1 AS T1 INNER JOIN
( SELECT user_id, MAX(date) AS date FROM Table1 GROUP BY user_id) AS T2
ON T1.user_id=T2.user_id AND T1.date=T2.date
SELECT books.id, books.title, books.year, COUNT(articles.book)
FROM books, articles
WHERE articles.book = books.id
GROUP BY books.id, books.title, books.year
SELECT books.id, books.title, books.year, COUNT(articles.book)
FROM books LEFT JOIN articles ON books.id=articles.book
GROUP BY books.id, books.title, books.year
SELECT id, code, base_id, block_id FROM Table
WHERE code=123456 AND base_id=??????? AND block_id=?????? LIMIT 0,3
UNION ALL
SELECT id, code, base_id, block_id FROM Table LIMIT 0,2
WHERE code=678901 AND base_id=??????? AND block_id=?????? LIMIT 0,2