473,396 Members | 1,967 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

retrieve a last value from sql

Hi,
Can any one tell me .. How to retrieve a last value from the database?
I tried the last function, but I just got the error.

Thanks in advance

Regards,
Syed Ahmed Hussain
Jul 29 '09 #1
6 4531
ziycon
384 256MB
Could try the below, not sure if it works in SQL though.
Expand|Select|Wrap|Line Numbers
  1. SELECT MAX(column) FROM tablename
Jul 29 '09 #2
Jerry Winston
145 Expert 100+
Correct me if i'm wrong, but do you mean last row entered into a table?
Expand|Select|Wrap|Line Numbers
  1. SELECT MAX(MySequentialIndexColumn) from [MyTable]
works based on the premise that MySequentialIndexColumn is an IDENTITY column continuously incremented with each addition to the table. Therefore, the highest value of the column should be the latest entry.

Here's my advice:

If it is important to know when a row was added to a table the time/date of insertion should be listed as a field. With the addition of a time/date field, you will be able to query your table based on the exact time rows were entered.
Aug 4 '09 #3
Both of you are right....

Thank you guys.. :)

Regards,

Syed Ahmed Hussain
Aug 5 '09 #4
OuTCasT
374 256MB
If you have an identity column then u could use

Expand|Select|Wrap|Line Numbers
  1. select @@Identity from myTable
Aug 7 '09 #5
So what will this query do?
select @@Identity from myTable
Aug 7 '09 #6
OuTCasT
374 256MB
if u have and identity column which set ur rows in order 1 2 3 4 5 etc
then it will pull the last value inserted in the database.

i add a index column like so

Expand|Select|Wrap|Line Numbers
  1. alter table MYTable
  2. Add TempID int IDENTITY(1,1)
Aug 11 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Prasad Karunakaran | last post by:
I am using the C# DirectoryEntry class to retrieve the Properties of an user object in the Active Directory. I need to get the First Name and Last Name as properties. I know it is not supported...
2
by: js | last post by:
I have a table rendered with XSLT. The first column has a radio button controls for user to make a selection for a particular row. All the values in the remaining columns are all concated with a...
6
by: Ada | last post by:
hello folks, is there a way to retrieve the highest value in the ArrayList? let say i have a value in the array: {1, 4, 15, 3, 7} it should return a value 15 as the result. i've looked at...
0
by: george_Martinho | last post by:
It seems that the ASP.NET Microsoft team didn't think about this!! The profilemanager class has the following methods: - DeleteInactiveProfiles. Enables you to delete all profiles older than a...
3
by: Rich | last post by:
Hello, I am populating a datagridview from a datatable and filtering the number of rows with a dataview object. Is there a way to retrieve the rows displayed by the datagridview into a separate...
6
by: Daz | last post by:
Hi everyone. Firstly, I apologise if this i not what you would call a PHP problem. I get quite confused as to what lives in which realm, so if this shouldn't be posted here, please suggest where...
1
maxamis4
by: maxamis4 | last post by:
Hello folks, Here is the backgroup. I am creating an agent that can find a user in LDAP and return the last logon date. Now i am not sure if with active directory you can user the...
3
by: David | last post by:
Hi, I have some code in my form as follows, to display 1 to 20 additional sets of fields to enter guest information. I am not sure how to retrieve these guests info so that I can post the info...
12
lifeisgreat20009
by: lifeisgreat20009 | last post by:
I am a newbie to Struts and JSP...I have been working on the code below for 5 hours now..I googled a lot but couldn't get much help so finally I am here.. Hoping of getting my problem solved. Please...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.