Topic: MYSQL数据库中查询记录的语句请帮助.

  Print this page

1.MYSQL数据库中查询记录的语句请帮助. Copy to clipboard
Posted by: SQL20000
Posted on: 2003-08-07 12:37

我要查询出MYSQL数据库中最后10条记录应该怎么写.
表名为gqxx

select * from gqxx order by id desc
这只会写出来这些.
请帮助谢谢.

2.Re:MYSQL数据库中查询记录的语句请帮助. [Re: SQL20000] Copy to clipboard
Posted by: SQL20000
Posted on: 2003-08-07 12:56

select top 10 from gqxx order by id desc
在MYSQL中是错误的。(在SQL2000中成立)

3.Re:MYSQL数据库中查询记录的语句请帮助. [Re: SQL20000] Copy to clipboard
Posted by: samx
Posted on: 2003-08-07 13:17

mysql>select count(*) from gqxx; //get the total records
mysql>select * from gqxx order by id desc limit (count(*)-9),10; //get what you want

For example, if you get total records from the first command by using count function: count(*)=30

the second command should be like:
mysql>select * from gqxx limit 21,10;

Of cause many commands are different between two different SQL servers, please check their manual or reference book if you get trouble.

And if you have more questions, please post them at "Database" . There are so many gurus. I myself is not one.

4.Re:MYSQL数据库中查询记录的语句请帮助. [Re: samx] Copy to clipboard
Posted by: SQL20000
Posted on: 2003-08-07 13:33

select * from gqxx limit 21,10;

我光执行这一条语句行不行呀..
在JSP页中.
我试了好使..

5.Re:MYSQL数据库中查询记录的语句请帮助. [Re: samx] Copy to clipboard
Posted by: SQL20000
Posted on: 2003-08-07 13:52

select * from gqxx order by id desc limit 10;
搞定了多谢高手.


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923