show the last id.

I have a select and i am not passing the orderid in the were clause I just want to select the last order id.

select orderid, name from table where userid=userid
order by orderid desc


orderid  name
179      john
178     john
how can i just select the 179 not the entire in  a select statement, is this possible.

Seven priceFull StackAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

One simple way of doing this if you are always going to order by OrderID DESC is to use TOP 1

   TOP 1 OrderID, Name
   UserID = @userID
   OrderID DESC

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Hi, try this :

select TOP 1 orderid  from table where userid=userid
order by orderid desc

This in case that your order id is an identity or a progresive int secuence.

Hope this help you!
Seven priceFull StackAuthor Commented:
Ok that sounds great but there is more than one row with orderid 179
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

How do you know which orderid is the last one then? Is there a date field?
Or do you want all rows with orderid 179 returned?
Seven priceFull StackAuthor Commented:
I was just about to suggest the date also. but can you read it to the seconds. if so how.?
Seven priceFull StackAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.