473,387 Members | 1,398 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,387 software developers and data experts.

select maximum in a table

Hi

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
3 1612
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
deric
92
You can also make use of the MAX function...
May 16 '08 #3
Delerna
1,134 Expert 1GB
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
  3.  
May 16 '08 #4

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

Similar topics

2
by: mr_burns | last post by:
hi, how do i do a SELECT statment that will just query a table to find the row with the maximum of a declared field. for example, if i have a table of customers and i would like to get the value...
5
by: MaJoHu | last post by:
I've got a list where u can select some products. It's something like this: <SELECT NAME='Product' MULTIPLE SIZE='10'> <% 'Get every possible item from items table SQL = "SELECT DISTINCT...
4
by: Mark | last post by:
good spam subject ;). anyway, i'm alittle stumped. i'm in need of putting together a query that gets the next highest salary ( select max ( sal ) - 1?, from an emp_sal type table. another...
0
by: Jan | last post by:
I store sql-commands in a database table. In the first step I get the sql command out of the database table with embedded sql. In the second step I try to execute the command, which i got from the...
4
by: Denis St-Michel | last post by:
Hello All, Hope some Guru will be able to help me with this. Let's take this example table A ------------------------------------------------------------------------------- id | ...
13
by: Ray Allison | last post by:
Is it bad practice to use 'Select * ' from a security perspective? Thanks for any advice. Ray
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
3
by: otac0n | last post by:
How can I select the maximum value from a field, but make sure that the value i want stays greater than a cetrain value? I currently have this: SELECT A.rating, B.rating,...
5
by: rAinDeEr | last post by:
Hi, I have a web application with a table to store terms and conditions of a Company. This may some times run into many pages and some times it may be just a few sentences. It is a character...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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,...

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.