Connecting Tech Pros Worldwide Forums | Help | Site Map

get value of last item in column?

andreas.hei@googlemail.com
Guest
 
Posts: n/a
#1: Mar 7 '07
How can I get the value of the last Item in a coums?
SELECT COLUMN FROM DATABASE ORDER BY COLUMN DESC?
something with Fields(0).value?

Thank you in advance


Plamen Ratchev
Guest
 
Posts: n/a
#2: Mar 7 '07

re: get value of last item in column?


You can use TOP 1 to return only 1 row (based on the ORDER BY), something
like this:

SELECT TOP 1 COLUMN FROM TABLE ORDER BY COLUMN DESC

Also, MIN(COLUMN) and MAX(COLUMN) may work depending on how you define last
item, like:

SELECT MAX(COLUMN) FROM TABLE

Regards,

Plamen Ratchev
http://www.SQLStudio.com


andreas.hei@googlemail.com
Guest
 
Posts: n/a
#3: Mar 12 '07

re: get value of last item in column?


Thank you very much, but my question is more like how to get the exact
VALUE of the field (not the minimum or maximum)?

is there a command/query for it?




On 7 mar, 18:54, "Plamen Ratchev" <Pla...@SQLStudio.comwrote:
Quote:
You can use TOP 1 to return only 1 row (based on the ORDER BY), something
like this:
>
SELECT TOP 1 COLUMN FROM TABLE ORDER BY COLUMN DESC
>
Also, MIN(COLUMN) and MAX(COLUMN) may work depending on how you define last
item, like:
>
SELECT MAX(COLUMN) FROM TABLE
>
Regards,
>
Plamen Ratchevhttp://www.SQLStudio.com

Greg D. Moore \(Strider\)
Guest
 
Posts: n/a
#4: Mar 12 '07

re: get value of last item in column?


<andreas.hei@googlemail.comwrote in message
news:1173689649.827708.218050@n33g2000cwc.googlegr oups.com...
Quote:
Thank you very much, but my question is more like how to get the exact
VALUE of the field (not the minimum or maximum)?
Not sure what you mean by the exact value of the field. How do you define
last item in column.

Generally that means the min or max value.

If you can give us some example data perhaps we can give a better solution?

Quote:
>
is there a command/query for it?
>
>
>
>
On 7 mar, 18:54, "Plamen Ratchev" <Pla...@SQLStudio.comwrote:
Quote:
>You can use TOP 1 to return only 1 row (based on the ORDER BY), something
>like this:
>>
>SELECT TOP 1 COLUMN FROM TABLE ORDER BY COLUMN DESC
>>
>Also, MIN(COLUMN) and MAX(COLUMN) may work depending on how you define
>last
>item, like:
>>
>SELECT MAX(COLUMN) FROM TABLE
>>
>Regards,
>>
>Plamen Ratchevhttp://www.SQLStudio.com
>
>


--
Greg Moore
SQL Server DBA Consulting
Email: sql (at) greenms.com http://www.greenms.com


Plamen Ratchev
Guest
 
Posts: n/a
#5: Mar 12 '07

re: get value of last item in column?


In addition to Greg's comments, this is why you can use TOP 1 and then based
on the ORDER BY define what you need to be selected in the result set.

Or maybe you mean the last inserted row... But a table is unordered set. You
would have to use a column that can determine what the last inserted row is
(the latest ID, date/time stamp, etc.).

Plamen Ratchev
http://www.SQLStudio.com



Closed Thread