I managed to cobble together a join statement to give me a single table that displays my entire database. Now I need to narrow the results down to just the last 30 days, but I cannot for the life of me figure out how to work this restriction into the query.
Right now I have:
select customers.name, customers.email, orderinfo.orderno, orderinfo.orderdate, status.state, orderinfo.lastupdate
from customers
where orderinfo.orderdate = curdate()
inner join orderinfo on customers.id=orderinfo.fk_id
inner join status on orderinfo.fk_code=status.code
order by customers.name;
…in an attempt to just narrow it down to showing me all the records for today, but even that is not working. I see there are a variety of ways of doing the 30-day thing but the part I’m having the most trouble with is just getting the WHERE clause to work at all in this query.
Thanks for any advice!
The
WHEREclause needs to go before theORDER BYand after all joins.