find date range containing today mysql join -


i have 2 tables, restaurants , orders, each restaurant has many orders

restaurants table id name   orders table id restaurant_id date status 

if date there no order - means there no row in orders table. if there order, status can 0, 1 or 2. each row in orders table represents 1 day.

i need find restaurants that, between 2013-08-15 , 2013-08-25(that includes current day - 2013-08-19 ) not have orders @ (which means there no appropriate row in orders table), or have order status 0 or 1, along these conditions order today should have status - 2. so, if restaurant not have order today or status not 2 - restaurant should not listed in result, if order today exists , status 2 result should contain restaurant orders list above-mentioned date range.

by query result without part of today's condition.

select r.`id`, r.`name` restaurants r left join orders o on r.id = o.restaurant_id , o.date between '2013-08-15' , '2013-08-25' o.id null or o.`status` = 0 or o.status = 1 

how can add condition ?

thanks

i queries separately , take union of results. exclude today query have, add separate query today. like:

select r.id, r.name restaurants r left join orders o on r.id = o.restaurant_id , o.date between '2013-08-15' , '2013-08-25' , o.date <> '2013-08-19' -- current day o.id null or o.status = 0 or o.status = 1 union select r.id, r.name restaurants r inner join orders o on r.id = o.restaurant_id , o.date = '2013-08-19' -- current day o.status = 2


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -