ecopetition Posted August 7, 2008 Share Posted August 7, 2008 Hi, I'm looking for a query that will let me check different rows of a database to see which one has the highest time (a time_posted column is present). I also need to set conditions. Something like: $sql = SELECT * FROM tablename WHERE post_number = $post_number AND time_posted = {{{highest number}}} $result = $resultvar[] What would I set {{{highest number}}} to? Link to comment https://forums.phpfreaks.com/topic/118671-simple-db-query-needed/ Share on other sites More sharing options...
obsidian Posted August 7, 2008 Share Posted August 7, 2008 You cannot have aggregates in your where clause that way, but you can sort on the time_posted column and limit to one: SELECT * FROM tablename WHERE post_number = $post_number ORDER BY time_posted DESC LIMIT 1; Link to comment https://forums.phpfreaks.com/topic/118671-simple-db-query-needed/#findComment-610972 Share on other sites More sharing options...
ecopetition Posted August 7, 2008 Author Share Posted August 7, 2008 Thanks but a silly question: what's an aggregate? Link to comment https://forums.phpfreaks.com/topic/118671-simple-db-query-needed/#findComment-610979 Share on other sites More sharing options...
obsidian Posted August 8, 2008 Share Posted August 8, 2008 Thanks but a silly question: what's an aggregate? An aggregate is any "grouping" of records, such as SUM, AVG, COUNT, etc. Link to comment https://forums.phpfreaks.com/topic/118671-simple-db-query-needed/#findComment-612019 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.