Can i get some help to clean up following query and possibly convert it to joins.
SELECT pd.id, pd.title, pd.vacation_type_ids, pd.auto_vacation_theme
FROM property_details pd
WHERE pd.company_id =247
AND pd.status = "active"
AND pd.id NOT
IN (
SELECT d.property_id
FROM property_discount d
WHERE (
(
d.start_date <= CAST( "2012-04-15" AS DATE )
AND d.end_date >= CAST( "2012-04-15" AS DATE )
AND d.start_date <= CAST( "2012-04-17" AS DATE )
AND d.end_date >= CAST( "2012-04-17" AS DATE )
)
OR (
d.start_date >= CAST( "2012-04-15" AS DATE )
AND d.start_date <= CAST( "2012-04-17" AS DATE )
)
OR (
d.end_date >= CAST( "2012-04-15" AS DATE )
AND d.end_date <= CAST( "2012-04-17" AS DATE )
)
)
)
I am not an expert with MySQL so sorry if i have did something wrong
This whole thing makes no sense to me.
The first block can get reduced to basically
start_date <= '2012-04-17' AND end_date >= '2012-04-17'. This case gets handled by the second and third block which is basicallystart_date BETWEEN '2012-04-15' AND '2012-04-17'respectivelyend_date BETWEEN '2012-04-15' AND '2012-04-17'.Do you really want an
ORbetween this, or rather anAND?You gave no information about your DB design, so I can only guess, if the following connection between these two tables is right.