Solved

Problem with SQL SELECT MAX

Posted on 2012-03-15
12
454 Views
Last Modified: 2012-03-15
Hi,

I'm trying to get the highest customerID number from a table so I can add 1 and have the next number to add a new record.

using "Select MAX (customerID) FROM T_Customers;"

I get a number that is not correct.  The highest customerID number is 11, but this query returns 9.

Thanks
0
Comment
Question by:taborrg
  • 7
  • 4
12 Comments
 
LVL 2

Expert Comment

by:costaf
ID: 37724318
that is wierd, the syntax of the sql command seems to be correct. are you sure ?
what kind of database are you using? where did you run this command?
0
 
LVL 1

Author Comment

by:taborrg
ID: 37724333
Yes - I've been retrying if for over an hour.  

When I try substituting other fields, it works fine.  Only on the primary key does it not work.

Select   MIN(customerID) FROM T_Customers  gives a "1" as it should.

I even rebooted.
0
 
LVL 2

Expert Comment

by:costaf
ID: 37724341
have you or anyone else made any changes to that table , that not have been commited yet?
0
 
LVL 1

Author Comment

by:taborrg
ID: 37724349
No.

Its a pretty simple setup - just me.
0
 
LVL 1

Author Comment

by:taborrg
ID: 37724371
When I recreate the table with only 5 records it works ok.
0
 
LVL 2

Expert Comment

by:costaf
ID: 37724381
what kind of data  type is associated with the custtomerid ? try to add more data and try again.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 1

Author Comment

by:taborrg
ID: 37724387
did that.  Many times.
0
 
LVL 1

Author Comment

by:taborrg
ID: 37724392
wait .. might be a type issue.
0
 
LVL 9

Expert Comment

by:bharrington83
ID: 37724401
Sounds like you are using a character field as opposed to a numeric field.  It would sort
1
10
11
12
2
3
4
5
7
8
9
0
 
LVL 2

Accepted Solution

by:
costaf earned 500 total points
ID: 37724406
i aggre with the comment of bharrington83. thats why i asked what data type was associated with the field used in the select max querie.
0
 
LVL 1

Author Comment

by:taborrg
ID: 37724407
Yep.  That's it

It's working now.
0
 
LVL 1

Author Closing Comment

by:taborrg
ID: 37724414
costaf,

You did put me onto the solution -  Thanks!
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now