SQL语句 怎样按排序后显示前三个

2024-12-03 23:41:26
推荐回答(3个)
回答1:

没有看到你的数据库conn连接啊:
@$conn = mysql_connect("yourHost","yourUserID","yourPassword");

$sql=mysql_query("select top 3 title from art_title join art_neirong on art_title.no=art_neirong.no order by last_update DESC;",$conn);
//echo $sql;
$i=0;
while($result=mysql_fetch_array($sql))
{
echo "

".$result['title']."
;
}
mysql_close($conn);

回答2:

根据SQL 的语法规则,先执行Select 部分,然后才Order by,所以根据你的要求应该
Select top 3 (a.*) from (select *from tablename order by col1)a

回答3:

select top 3 from table order by