开发者

sql order by date before selection query help

I'm about to jump into some SQL query code that I haven't attempted before, basically my tables will have rows with dates that will not be in order, what I want to do is firstly order the table by date, then select 9 rows that will be older than a specified date.

So the query I'm considering running will look something like this:

$result = mysql_query("SELECT * 
                         FROM links 
                     ORDER BY date DESC 
                        WHERE date < '$olderdate' 
                        LIMIT 9"); 

will 开发者_如何学JAVAthis work? or is there a better way of pulling this off?


You have to put the WHERE clause before the ORDER BY one:

$result=mysql_query("select * from links where date<'$olderdate' order by date desc limit 9");


Use order by after where condition

select * from links where date<'$olderdate' order by date desc limit 9

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜