-$result = SQL_QUERY("SELECT DISTINCT d.id, d.admin_id, a.login, d.title, d.descr, d.template, d.start_time, d.end_time, d.min_users, d.min_prices
-FROM `{!_MYSQL_PREFIX!}_rallye_data` AS d, `{!_MYSQL_PREFIX!}_admins` AS a
-WHERE d.admin_id=a.id".$ADMIN." AND d.notified='Y'
-ORDER BY d.end_time LIMIT 1", __FILE__, __LINE__);
+$result = SQL_QUERY("SELECT
+ d.id, d.admin_id, a.login, d.title, d.descr, d.template, d.start_time, d.end_time, d.min_users, d.min_prices
+FROM
+ `{?_MYSQL_PREFIX?}_rallye_data` AS d
+INNER JOIN
+ `{?_MYSQL_PREFIX?}_admins` AS a
+ON
+ d.admin_id=a.id
+WHERE
+ d.notified='Y'" . $ADD . "
+ORDER BY
+ d.end_time
+LIMIT 1", __FILE__, __LINE__);