Click to See Complete Forum and Search --> : Selecting last x entries query


Dali
01-20-2008, 06:18 PM
Once again i can't figure out what's wrong with the query i'm trying to make. Its complicated (for me, not being a programer) as it is, and i need to add a date range on it. I have a date_column (mysql db), with 0000-00-00 as default.
The query so far is (and it works just fine):
$query = "
(SELECT pic, price, group, min(nr) AS nr FROM productinfo
WHERE (group>0)
AND (nr LIKE '10%')
AND ((quantity >= 0 and out!='Y') or (quantity > 0 and out ='Y')) GROUP BY group)
UNION
(SELECT pic, price, group, nr FROM productinfo WHERE (group=0)
AND (artnr LIKE '10%')
AND ((quantity >= 0 and out!='Y') or (quantity > 0 and out ='Y')))
ORDER BY nr";

Now i need to show the last X entries, using the same query. I've tried adding
date_column BETWEEN CURDATE() and DATE_SUB(CURDATE(),INTERVAL 30 DAY)
to the query (if we take a last 30days example), but i guess i'm missing some () somewhere, i'm really bad with the basic syntax.

Any help is highly appreciated