SELECT SQL_CALC_FOUND_ROWS a.id, b.id, b.meta_name, b.meta_value
FROM a
LEFT OUTER JOIN (SELECT * FROM b ORDER BY b.id DESC) b ON a.id = b.meta_value
WHERE b.meta_name = '***'
GROUP BY a.id
ORDER BY a.id DESC
LIMIT 0, 20
$res = mysql_query("SELECT FOUND_ROWS()");
$count = mysql_result($res, 0);
var_dump($count); // string(1) "0"
SELECT SQL_CALC_FOUND_ROWS b.id, b.meta_name, b.meta_value
FROM b WHERE b.meta_name = '***'
ORDER BY b.meta_value DESC
LIMIT 0, 20;
SELECT FOUND_ROWS()
SELECT SQL_CALC_FOUND_ROWS a.id,
(SELECT b.meta_value from b where b.meta_name=a.id order by b.id limit 1) as lastprice
FROM a LIMIT 0, 20
SELECT SQL_CALC_FOUND_ROWS *
FROM offers
LEFT OUTER JOIN (SELECT * FROM `offers_meta` ORDER BY `offers_meta`.`id` DESC) offers_meta
ON offers.offer_id = offers_meta.offer_id
WHERE (offers_meta.offer_id IS NOT NULL AND offers_meta.meta_name = 'nacenka') or (offers.master = 0 or offers.master = {$_SESSION['user_id']})
$sort and offers.hold < $datenow and offers.status = 'on sale'
GROUP BY offers.offer_id
ORDER BY master DESC
$limit
$res = mysql_query("SELECT SQL_CALC_FOUND_ROWS offers.offer_id, offers.ref, offers.carat, offers.color, offers.clarity, offers.lab, offers.price, offers.master, offers_meta.meta_value, offers_meta.id
FROM offers
LEFT OUTER JOIN (SELECT * FROM `offers_meta` ORDER BY `offers_meta`.`id` DESC) offers_meta
ON offers.offer_id = offers_meta.offer_id
WHERE (offers_meta.offer_id IS NOT NULL AND offers_meta.meta_name = 'nacenka') or (offers.master = 0 or offers.master = {$_SESSION['user_id']})
$sort and offers.hold < $datenow and offers.status = 'on sale'
GROUP BY offers.offer_id
ORDER BY master DESC
$limit");
$pages = mysql_query("SELECT FOUND_ROWS()");
$pages = mysql_result($pages, 0);
SELECT SQL_CALC_FOUND_ROWS
*,
(
SELECT
offers_meta.meta_value
FROM
offers_meta
WHERE
offers_meta.meta_name = 'nacenka' AND offers.offer_id = offers_meta.offer_id
ORDER BY
offers_meta.id
LIMIT 1
) AS lastprice
FROM
offers
WHERE
(lastprice IS NOT NULL) or (
offers.master = 0 OR offers.master = 4
) AND offers.hold < 1500817610 AND offers.status = 'on sale'
ORDER BY
offers.price
DESC
LIMIT 0, 25
SELECT SQL_CALC_FOUND_ROWS *
FROM offers
LEFT OUTER JOIN (SELECT * FROM `offers_meta` ORDER BY `offers_meta`.`id` DESC) offers_meta
ON offers.offer_id = offers_meta.offer_id
WHERE (offers_meta.offer_id IS NOT NULL AND offers_meta.meta_name = 'nacenka') or (offers.master = 0 or offers.master = {$_SESSION['user_id']})
$sort and offers.hold < $datenow and offers.status = 'on sale'
GROUP BY offers.offer_id
ORDER BY master DESC
$limit
SELECT SQL_CALC_FOUND_ROWS *,
(SELECT offers_meta.meta_value FROM offers_meta WHERE offers_meta.meta_name = 'nacenka' AND offers.offer_id = offers_meta.offer_id ORDER BY offers_meta.id LIMIT 1) AS lastprice
FROM offers WHERE
(
offers.master = 0 OR offers.master = {$_SESSION['user_id']}
) AND (lastprice != NULL)
AND
offers.hold < $datenow
AND offers.status = 'on sale'
ORDER BY offers.price DESC $limit
SELECT SQL_CALC_FOUND_ROWS
*
FROM
(SELECT
*,
(
SELECT
offers_meta.meta_value
FROM
offers_meta
WHERE
offers_meta.meta_name = 'nacenka'
AND offers.offer_id = offers_meta.offer_id
ORDER BY offers_meta.id
LIMIT 1
) AS lastprice
FROM
offers
WHERE
offers.hold < 1500817610
AND offers.status = 'on sale'
) zz
WHERE
zz.lastprice IS NOT NULL
OR zz.master IN (0,4)
ORDER BY zz.price DESC
LIMIT 0, 25