Author |
Topic |
harshilshah
Starting Member
8 Posts |
Posted - 2012-12-26 : 04:18:23
|
I have some 70 database entries in table weightweight------ 45.645.3423.56 . . . ............66.7834.6778.99I want to display the last 10 entries. Can any1 help me with the query.IM woeking with sql 5.5 |
|
asif372
Posting Yak Master
100 Posts |
Posted - 2012-12-26 : 04:43:24
|
SelectTOP (10)WeightFrom TableNameORDER BY Weight DESC |
|
|
harshilshah
Starting Member
8 Posts |
Posted - 2012-12-26 : 04:56:35
|
SQL error: function tablename.top does not exist... what to do now |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-12-26 : 05:03:59
|
quote: Originally posted by harshilshah SQL error: function tablename.top does not exist... what to do now
Are you using sql server? I dont think so seeing the error message------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2012-12-26 : 05:10:09
|
quote: Originally posted by harshilshah I have some 70 database entries in table weightweight------ 45.645.3423.56 . . . ............66.7834.6778.99I want to display the last 10 entries. Can any1 help me with the query.IM woeking with sql 5.5
If you are using MySQL 5.5, then use SELECT * FROM TableName ORDER BY weight DESC LIMIT 10;--Chandu |
|
|
harshilshah
Starting Member
8 Posts |
Posted - 2012-12-26 : 05:24:26
|
@bandi : the query give me the values in descending order. I dont want it to be displayed in descending/ascending order,I want it to be displayed the same as it is in stored in table.@visakh16 : im using sql 5.5 not sql server:) |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2012-12-26 : 05:31:25
|
quote: Originally posted by harshilshah @bandi : the query give me the values in descending order. I dont want it to be displayed in descending/ascending order,I want it to be displayed the same as it is in stored in table.@visakh16 : im using sql 5.5 not sql server:)
Then try this: SELECT * FROM TableName LIMIT 10;This is SQL Server related forum.. You can get quick responses by posting your queries in MySql related forums--Chandu |
|
|
harshilshah
Starting Member
8 Posts |
Posted - 2012-12-26 : 05:36:32
|
@chandu : ur query above gives me top 10 values, I want the bottom 10. because when a new value is inserted it is stored at the bottom of the table. |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2012-12-26 : 06:22:55
|
quote: Originally posted by harshilshah @chandu : ur query above gives me top 10 values, I want the bottom 10. because when a new value is inserted it is stored at the bottom of the table.
Try this...Method1:SELECT fieldlist FROM table LIMIT (SELECT COUNT(*) FROM table)-10 ,10If the above gives error, find the total number of rows and replace this part ((SELECT COUNT(*) FROM table)) with that count........Method2:If there is auto incremented column( or created time column) in that table you can write as follows: SELECT columnName FROM TableName ORDER BY AuoIncColName DESC LIMIT 10--Chandu |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2012-12-26 : 12:35:20
|
More to the point, tables are unordered sets. There is no concept of first or last without applying an ORDER BY clause. If you can't do that, then you are out of luck. Granted, different version of SQL might have some "hidden" column that you might be able to use, but that is not a good design. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-12-26 : 23:06:25
|
quote: Originally posted by harshilshah @bandi : the query give me the values in descending order. I dont want it to be displayed in descending/ascending order,I want it to be displayed the same as it is in stored in table.@visakh16 : im using sql 5.5 not sql server:)
then you're in wrong forum.This is MS SQL server forum and we deal with t-sql mostly------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|