RE: Deleted rows

2005-08-18 Thread emierzwa
: Thursday, August 18, 2005 10:18 AM To: [EMAIL PROTECTED] Cc: Scott Hamm; 'Mysql ' Subject: Re: Deleted rows Scott, Shawn, >The OP would like to detect that 4,5,6, and 7 are missing from the >sequence. Your query would have only found that 7 was missing. Right! For sequences longer

Re: Deleted rows

2005-08-18 Thread Peter Brawley
Scott, Shawn, >The OP would like to detect that 4,5,6, and 7 are missing from the >sequence. Your query would have only found that 7 was missing. Right! For sequences longer than 1 you need something like... SELECT   a.id+1 AS 'Missing From',   MIN(b.id)-1 AS 'To' FROM test AS a, test AS

Re: Deleted rows

2005-08-18 Thread Scott Hamm
On 8/18/05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > > Peter, > > Your query may work for data with single-row gaps (like his example data) > but it will not work if the sequence skips more than one number. > > Look at this sequence: 1,2,3,8,9,10 > > The OP would like to detect tha

Re: Deleted rows

2005-08-18 Thread SGreen
Peter, Your query may work for data with single-row gaps (like his example data) but it will not work if the sequence skips more than one number. Look at this sequence: 1,2,3,8,9,10 The OP would like to detect that 4,5,6, and 7 are missing from the sequence. Your query would have only found t

Re: Deleted rows

2005-08-18 Thread Peter Brawley
Scott, >How do I execute a query that shows missing ID's like so: SELECT id AS i FROM tbl WHERE i <> 1 AND NOT EXISTS(   SELECT id FROM tbl WHERE id = i - 1 ); PB - Scott Hamm wrote: If I got a table as follows: ID foo 1 12345 2 12346 4 12348 6 12349 7 12388 9 12390 How do I exe

Re: Deleted rows

2005-08-18 Thread SGreen
Scott Hamm <[EMAIL PROTECTED]> wrote on 08/18/2005 08:59:00 AM: > If I got a table as follows: > > > ID foo > 1 12345 > 2 12346 > 4 12348 > 6 12349 > 7 12388 > 9 12390 > How do I execute a query that shows missing ID's like so: > > 3 > 5 > 8 > > I wouldn't expect for it to show deleted data th