MySQL Select last 7 days

The WHERE clause is misplaced, it has to follow the table references and JOIN operations. Something like this: FROM tartikel p1 JOIN tartikelpict p2 ON p1.kArtikel = p2.kArtikel AND p2.nNr = 1 WHERE p1.dErstellt >= DATE(NOW() – INTERVAL 7 DAY) ORDER BY p1.kArtikel DESC EDIT (three plus years later)    The above essentially answers the question … Read more

MySQL how to fill missing dates in range?

MySQL doesn’t have recursive functionality, so you’re left with using the NUMBERS table trick – Create a table that only holds incrementing numbers – easy to do using an auto_increment: DROP TABLE IF EXISTS `example`.`numbers`; CREATE TABLE `example`.`numbers` ( `id` int(10) unsigned NOT NULL auto_increment, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; Populate the table … Read more

Oracle DateTime in Where Clause?

Yes: TIME_CREATED contains a date and a time. Use TRUNC to strip the time: SELECT EMP_NAME, DEPT FROM EMPLOYEE WHERE TRUNC(TIME_CREATED) = TO_DATE(’26/JAN/2011′,’dd/mon/yyyy’) UPDATE: As Dave Costa points out in the comment below, this will prevent Oracle from using the index of the column TIME_CREATED if it exists. An alternative approach without this problem is … Read more