[vox-tech] MySQL 3.x - deleting orphan rows & datetime()

Jeff Newmiller vox-tech@lists.lugod.org
Fri, 7 May 2004 15:49:39 -0700 (PDT)


On Fri, 7 May 2004, Foo Lim wrote:

> On Fri, 7 May 2004, David Siedband wrote:
> 
> > Greetings,
> > 
> > I have two questions - using MySQL 3.x
> > 
> > [1] I'm trying to craft an SQL query to delete orphan rows in index 
> > tables
> > 
> > something like:
> > 
> > delete from DocWords left join Docs on Docs.ID = DocWords.DocID where 
> > Doc.ID is null
> > 
> > Any suggestions how to do this?
> 
> Hi David,
> 
> Try using a subquery:
> 
> delete from DocWords
> where DocID not in
> (select ID from Docs);

Subqueries are not implemented in MySQL 3.x.

The manual recommends a workaround based on an external procedural
language constructing the delete statement(s):

http://dev.mysql.com/doc/mysql/en/Deleting_from_related_tables.html

> > [2] Is it possible to emulate the functionality of difftime() in MySQL 
> > 3.x without using a scripting language?
> 
> I will defer this to someone who knows more than I do...

Or someone silly enough to peruse the manual for David?

See DATE_SUB...

http://dev.mysql.com/doc/mysql/en/Date_and_time_functions.html

---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil@dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...2k
---------------------------------------------------------------------------