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? Quote Link to comment 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; Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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.