table name: date fiels name: news_date news_date ----------- 2009-12-11 2009-12-31 2009-12-31 2010-01-01 2010-01-01 2010-02-01 2010-02-01 2010-02-03 2010-02-03 2010-02-03 I want to run a query that will result second highest 'news_date'. That means '2010-02-01' will produce (only one date/row & not all row of same date) Would you please tell me what will be the Query?
Simple as pie! SELECT MAX(news_date) FROM date WHERE news_date NOT IN (SELECT MAX(news_date) FROM date) Code (markup): or SELECT MAX(news_date) FROM ( SELECT news_date FROM date MINUS SELECT MAX(news_date) FROM date ) Code (markup):
date is sql data type and date() is a function, so it's not good idea to use this as a table name... However, simply: SELECT DISTINCT news_date FROM `date` ORDER BY news_date DESC LIMIT 1,1; Code (markup):