[Cppcms-users] Bizarre prepared statement problem
Brought to you by:
artyom-beilis
From: <ele...@ex...> - 2012-05-21 03:52:11
|
I'm truly stumped by this SQL query. This works as expected: SELECT * FROM af_scheduled_items i INNER JOIN af_scheduled_items_history h1 ON h1.root_id=i.id WHERE h1.date_fitted <= '2012-05-17 23:59:59' AND h1.id IN (SELECT max(h2.id) FROM af_scheduled_items_history h2 WHERE h2.date_fitted <= '2012-05-17 23:59:59' AND h2.root_id=i.id) AND h1.aircraft_id = ? ORDER BY i.id ASC Returns 2 rows which is what's expected. If I replace the h2.date_fitted with ? SELECT * FROM af_scheduled_items i INNER JOIN af_scheduled_items_history h1 ON h1.root_id=i.id WHERE h1.date_fitted <= '2012-05-17 23:59:59' AND h1.id IN (SELECT max(h2.id) FROM af_scheduled_items_history h2 WHERE h2.date_fitted <= ? AND h2.root_id=i.id) AND h1.aircraft_id = ? ORDER BY i.id ASC This returns 1 row. And if I replace both date_fitted dates with ? SELECT * FROM af_scheduled_items i INNER JOIN af_scheduled_items_history h1 ON h1.root_id=i.id WHERE h1.date_fitted <= ? AND h1.id IN (SELECT max(h2.id) FROM af_scheduled_items_history h2 WHERE h2.date_fitted <= ? AND h2.root_id=i.id) AND h1.aircraft_id = ? ORDER BY i.id ASC This returns sometimes 1 row, sometimes 2 rows. Can someone with enough wisdom explain this? |