koreets2011
Full Member | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору Добрый день уважаемые форумчане! Я тут на быдлокодил запрос, и что-то мне подсказывает, что его срочно нужно оптимизировать. Ибо выглядит он как-то не кашерно, в общем, вот он: Код: SELECT COUNT(*) AS 'total', /* Выборка 1 */ (SELECT COUNT(*) FROM `forum_topic` WHERE topic = 'topic1') AS 'topic1_count', (SELECT datetime FROM `forum_topic` WHERE topic = 'topic1' ORDER BY datetime DESC LIMIT 1) AS 'topic1_update', (SELECT author FROM `forum_topic` WHERE topic = 'topic1' ORDER BY datetime DESC LIMIT 1) AS 'topic1_author', (SELECT nametopic FROM `forum_topic` WHERE topic = 'topic1' ORDER BY datetime DESC LIMIT 1) AS 'topic1_nametopic', (SELECT ID FROM `forum_topic` WHERE topic = 'topic1' ORDER BY datetime DESC LIMIT 1) AS 'topic1_ID', /* Выборка 2 */ (SELECT COUNT(*) FROM `forum_topic` WHERE topic = 'topic2') AS 'topic2_count', (SELECT datetime FROM `forum_topic` WHERE topic = 'topic2' ORDER BY datetime DESC LIMIT 1) AS 'topic2_update', (SELECT author FROM `forum_topic` WHERE topic = 'topic2' ORDER BY datetime DESC LIMIT 1) AS 'topic2_author', (SELECT nametopic FROM `forum_topic` WHERE topic = 'topic2' ORDER BY datetime DESC LIMIT 1) AS 'topic2_nametopic', (SELECT ID FROM `forum_topic` WHERE topic = 'topic2' ORDER BY datetime DESC LIMIT 1) AS 'topic2_ID' FROM `forum_topic` | И таких "Выборок" (специально закомментировал в коде) 10! Натолкните на мысли |