October 16, 2007 at 2:12 am
Ive a table I'd like to get the last entry from if the field contains data, is this possible with TOP
field1 field2 field3
john George Fred
Alice Joan
I'd like to do say select top on field2 and get George, but if I do select top on field3 I'd get Joan, is this possible?
October 16, 2007 at 2:49 am
1) keep in mind there is no order in a table's rows.
If you want results handled in a certain order, you should use an order by clause in your query.
2) a top-clause works at row-level. It will return the top N rows and stop further processing of the resultset.
So I don't think top will solve your question. Maybe some kind of max function can help out.
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
October 16, 2007 at 2:54 am
so could I not put a id field in and do something like select top from feild2 where field2 is not null order by id?
October 16, 2007 at 3:22 am
Yes you can, but will it give you the result you expect ?
select top 1 field2
from yourtable
where field2 is not null
order by id -- if id is deterministice in the way you want in this case
It all depends on how strict you apply the concept of keys or surrogate keys and thier relation to a point time.
If you have a column "datetimecreated", maybe that might serve you better.
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
October 16, 2007 at 4:08 am
many thanks, I'll give it a try. And thanks for getting back to me so quick
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply