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 Quote 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' Quote 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 ??? Quote 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 Quote 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... Quote Link to comment https://forums.phpfreaks.com/topic/158234-php-sql-subquery/#findComment-834720 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.