Miko Posted May 15, 2009 Share Posted May 15, 2009 Hello, I'm trying to make a query that select's the max date: my query is like this: SELECT MAX(scandate) AS datum FROM STATUSDATA WHERE depot = '$pkdepot' AND pknr BETWEEN '$pknv' AND '$pknb' this query isn't a problem, but I would like to echo the column depot also. I know that I can do that with another query, but I want that it is done with 1 query. Thanks Link to comment https://forums.phpfreaks.com/topic/158234-php-sql-subquery/ Share on other sites More sharing options...
trq Posted May 15, 2009 Share Posted May 15, 2009 SELECT MAX(scandate) AS datum, depot FROM STATUSDATA WHERE depot = '$pkdepot' AND pknr BETWEEN '$pknv' AND '$pknb' Link to comment https://forums.phpfreaks.com/topic/158234-php-sql-subquery/#findComment-834593 Share on other sites More sharing options...
Miko Posted May 15, 2009 Author Share Posted May 15, 2009 hi, thanks for the respons, but it doesn't work ??? Link to comment https://forums.phpfreaks.com/topic/158234-php-sql-subquery/#findComment-834596 Share on other sites More sharing options...
kickstart Posted May 15, 2009 Share Posted May 15, 2009 Hi Presuming you want the max date for each depot (would be meaningless otherwise):- SELECT MAX(scandate) AS datum, depot FROM STATUSDATA WHERE depot = '$pkdepot' AND pknr BETWEEN '$pknv' AND '$pknb' GROUP BY depot All the best Keith Link to comment https://forums.phpfreaks.com/topic/158234-php-sql-subquery/#findComment-834604 Share on other sites More sharing options...
luca200 Posted May 15, 2009 Share Posted May 15, 2009 It looks to me like it's meaningless anyway, as far as 'depot' is in the WHERE condition... Link to comment https://forums.phpfreaks.com/topic/158234-php-sql-subquery/#findComment-834720 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.