[thelist] Iterate through result set - Is this possible? (SQL)

Mark Mandel mark.mandel at gmail.com
Tue May 31 02:20:28 CDT 2005


You are looking for date_sub:
http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html

HTH

Mark

On 5/31/05, Burhan Khalid <thelist at meidomus.com> wrote:
> Hello Everyone:
> 
>    I've run into a bit of a logic problem with SQL, and I don't think
> the solution is with SQL.  Hopefully someone can clear this up.
> 
>    I want to find the two sets of dates that differ by atleast 7 days.
> 
>    There are two tables, halls_events (hallid, eventid) and events (id,
> name, start_date, end_date)
> 
>    So far, I've managed to get the correct start dates for all events
> that are in a particular hall with the following (MySQL):
> 
>    SELECT start_date FROM events WHERE id IN (SELECT eventid FROM
> halls_events WHERE hallid = 2);
> 
>    What I would like to do is something like :
> 
>    SELECT start_date FROM events WHERE id IN (SELECT eventid FROM
> halls_events WHERE hallid = 2) AND DATEDIFF(start_date,start_date) > 7;
> 
>    Basically, loop through the results and compare each pair of
> start_dates. The above doesn't work.  Is this something that I need to
> solve on the server side? Or am I missing some SQL magic?
> 
> Thanks,
> Burhan

-- 
E: mark.mandel at gmail.com
W: www.compoundtheory.com
ICQ: 3094740


More information about the thelist mailing list