All pastes #435497 Raw Edit

Someone

public text v1 · immutable
·published 2007-04-11 23:19 UTC
rendered paste body
/* Countries that have states newer than 1 day */
SELECT countries.id, states.created FROM countries
INNER JOIN states ON countries.id = states.country_id
AND states.created >= DATE_SUB(CURDATE(),INTERVAL 1 DAY)

UNION

/* Countries that have states that have counties newer than 1 day */
SELECT countries.id, counties.created FROM countries
INNER JOIN states ON countries.id = states.country_id
INNER JOIN counties ON states.id = counties.state_id
AND counties.created >= DATE_SUB(CURDATE(),INTERVAL 1 DAY)

UNION
/* Countries that have states that have counties that have cities newer than 1 day */SELECT countries.id, states.id, counties.id, cities.id, cities.created, cities.name FROM countries
INNER JOIN states ON countries.id = states.country_id
INNER JOIN counties ON states.id = counties.state_id
INNER JOIN cities ON counties.id = cities.county_id 
AND cities.created >= DATE_SUB(CURDATE(),INTERVAL 1 DAY)