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

Burhan Khalid thelist at meidomus.com
Tue May 31 02:55:58 CDT 2005


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

I don't think this will work, because I don't see how I can have the 
query step through the resulting start_dates to apply this (or other 
function).



> 
> 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
> 
> 



More information about the thelist mailing list