连初级都算不上的代码小白 2023-06-30 22:09 采纳率: 52.4%
浏览 10
已结题

sql的top语句会报错


mysql> select * from newstu;
+------+------+------+
| id   | name | age  |
+------+------+------+
|   15 | 张三 |   18 |
|   12 | 李四 |   20 |
|   13 | 王五 |   22 |
|   14 | 六六 |   23 |
+------+------+------+

以上是我的table
以下是报错信息

mysql> select top 2 * from newstu;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '2 * from newstu' at line 1

  • 写回答

2条回答 默认 最新

  • Huazie 优质创作者: 编程框架技术领域 2023-06-30 22:21
    关注

    mysql 要用 limit 语句

    -- 从newstu 表中选择前 2 条记录
    select * from newstu limit 2; 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 7月8日
  • 已采纳回答 6月30日
  • 创建了问题 6月30日