Wierd query result on MySQL 5 system

This is a discussion on Wierd query result on MySQL 5 system within the MySQL Database forums, part of the Database Forums category; I have the following table (complete with sample data). When I run the query below on a mysql 4.1....


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-04-2006
Paul Lautman
 
Posts: n/a
Default Wierd query result on MySQL 5 system

I have the following table (complete with sample data).
When I run the query below on a mysql 4.1.14 system, the only row returned
is row 4 as expected.
However, when I run the same query on a mysql 5.0.19 system, I get rows 2, 3
& 4; which is not what I would expect.
I have found that if I replace the "date_add( Reminder_Sent, INTERVAL 7
DAY )" with a hard coded '2006-01-15', then I get the expected row 4 only,
but that defeats the object of the query as the dates in Reminder_Sent are
not normally always the same.

Can anyone point me to what is going on here?

TIA
Regards
Paul Lautman


CREATE TABLE `balls_in_play2` (
`Ball_Number` tinyint(2) NOT NULL default '0',
`Name` varchar(50) NOT NULL default '',
`email` varchar(50) NOT NULL default '',
`Expiry_Date` date NOT NULL default '0000-00-00',
`Reminder_Sent` date NOT NULL default '0000-00-00',
PRIMARY KEY (`Ball_Number`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `balls_in_play2`
--

INSERT INTO `balls_in_play2` (`Ball_Number`, `Name`, `email`, `Expiry_Date`,
`Reminder_Sent`) VALUES
(1, 'John Doe', '', '2007-03-31', '2006-01-01'),
(2, 'Hilary Smith', '', '2006-11-04', '2006-01-01'),
(3, 'Wendy Jones', '', '2006-10-28', '2006-01-01'),
(4, 'Fred Brown', '', '2006-05-06', '2006-01-01');

SELECT *
FROM balls_in_play2
WHERE (expiry_date BETWEEN date_add( Reminder_Sent, INTERVAL 7 DAY ) AND
date_add( current_date, INTERVAL 7 DAY ));


Reply With Quote
  #2 (permalink)  
Old 05-04-2006
Paul Lautman
 
Posts: n/a
Default Re: Wierd query result on MySQL 5 system

To see the problem first hand, I have set up
http://www.sunnyacres.co.uk/bb/bbqt.php
where you can run the query below to see the results.
You can also run the query

SELECT *, date_add( Reminder_Sent, INTERVAL 7 DAY ), date_add( current_date,
INTERVAL 7 DAY ) FROM balls_in_play2 WHERE (expiry_date BETWEEN date_add(
Reminder_Sent, INTERVAL 7 DAY ) AND date_add( current_date, INTERVAL 7
DAY ));

to see that the expiry_date is not within the bounds.

Paul Lautman wrote:
> I have the following table (complete with sample data).
> When I run the query below on a mysql 4.1.14 system, the only row
> returned is row 4 as expected.
> However, when I run the same query on a mysql 5.0.19 system, I get
> rows 2, 3 & 4; which is not what I would expect.
> I have found that if I replace the "date_add( Reminder_Sent, INTERVAL
> 7 DAY )" with a hard coded '2006-01-15', then I get the expected row 4
> only, but that defeats the object of the query as the dates in
> Reminder_Sent are not normally always the same.
>
> Can anyone point me to what is going on here?
>
> TIA
> Regards
> Paul Lautman
>
>
> CREATE TABLE `balls_in_play2` (
> `Ball_Number` tinyint(2) NOT NULL default '0',
> `Name` varchar(50) NOT NULL default '',
> `email` varchar(50) NOT NULL default '',
> `Expiry_Date` date NOT NULL default '0000-00-00',
> `Reminder_Sent` date NOT NULL default '0000-00-00',
> PRIMARY KEY (`Ball_Number`)
> ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
>
> --
> -- Dumping data for table `balls_in_play2`




Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 07:40 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0