By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,364 Members | 1,343 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,364 IT Pros & Developers. It's quick & easy.

select maximum in a table

P: 70

i have table empid,empname...........etc.In my webform i have empname etc.but not empid.

i empid is inserted based on the maximum of the empid in the table.At first my table was empty.then how should i find maximum of table.

pls help me.
May 15 '08 #1
Share this Question
Share on Google+
3 Replies

P: 42
Try this
Expand|Select|Wrap|Line Numbers
  1. select top 1 from mytable order by empid desc
This will give you the bigest empid number!
May 15 '08 #2

P: 92
You can also make use of the MAX function...
May 16 '08 #3

Expert 100+
P: 1,134
You can also make use of the MAX function...
and a benefit for that is you can set a starting value for when the table is empty.
Suppose that a number sequence should start at 1000 an the table is empty then
Expand|Select|Wrap|Line Numbers
  1. SELECT isnull(max(id),1000) as id 
  2. FROM YourTable
May 16 '08 #4

Post your reply

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