views:

40

answers:

3

I have this simple query:

SELECT High, Low FROM prices 
WHERE Stock = 'XXX' and Date = '2010-02-05' and Low <= 14.88 AND High >= 14.88

Now for 2010-02-05 Low=14.88 and High=15.88

How come the query return empty? It's running on MySQL 5.0.41

Thanks!

+4  A: 

I would check each criteria carefully,

First I would remove all except Stock, then if that returned data, I would include Date, after running that ensuring that data was returned I would include Low (repeat process) and finally High.

When the query stops returning data you should look into why it's stopped. Perhaps it's the date portion. IE if the date on Table Prices is '2010-02-05 12:35:17' it won't match '2010-02-05'

Maybe Stock isn't set to 'XXX'

Please test these and post more information if the issue persists.

Nathan Koop
+1 For Simple Incremental testing !
Misnomer
I totally agree!! My money is on the Date issue. instead of Date = ..... it should be the MySQL equivalent of Oracle's trunc(date) = ... I bet the one that seems missing is after midnight on the date given!!!
sql_mommy
A: 

Does the select return the row if you remove the high and low checks? The format of your Date clause has me concerned that you're just not matching that row at all. (Just a stab at it, really.)

Dante617
A: 

Either number rounding as in 14.881 or date with a timestammp as Nathan Koop states.

Mark Schultheiss