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

Help on select a Last Inserted Record

rajiv07
141 100+
Hi to all,
I want to know how to select a last inserted record which is the primary key is not an integer.

my table

ramstr(Primary)----name--service

XTC01-------Rajiv---service

XTC02------kumar--Service

Here i want to select the last inserted record.(XTC02------kumar--Service).

Is any idea Please.

Thanks.
RajivGandhi.
Feb 4 '08 #1
13 4399
amitpatel66
2,367 Expert 2GB
Hi to all,
I want to know how to select a last inserted record which is the primary key is not an integer.

my table

ramstr(Primary)----name--service

XTC01-------Rajiv---service

XTC02------kumar--Service

Here i want to select the last inserted record.(XTC02------kumar--Service).

Is any idea Please.

Thanks.
RajivGandhi.
Try to take the MAX(primary key column) and check if it works??

Expand|Select|Wrap|Line Numbers
  1.  
  2. SETEC * from my_table WHERE ramstr = (SELECT MAX(ramstr) FROM my_table);
  3.  
  4.  
Feb 4 '08 #2
rajiv07
141 100+
Try to take the MAX(primary key column) and check if it works??

Expand|Select|Wrap|Line Numbers
  1.  
  2. SETEC * from my_table WHERE ramstr = (SELECT MAX(ramstr) FROM my_table);
  3.  
  4.  
It's working fine.Thank You for such a fast reply.

Regards
RajivGandhi
Feb 4 '08 #3
amitpatel66
2,367 Expert 2GB
It's working fine.Thank You for such a fast reply.

Regards
RajivGandhi
You are Welcome :)

Amit
Feb 4 '08 #4
r035198x
13,262 8TB
Try to take the MAX(primary key column) and check if it works??

Expand|Select|Wrap|Line Numbers
  1.  
  2. SETEC * from my_table WHERE ramstr = (SELECT MAX(ramstr) FROM my_table);
  3.  
  4.  
Wouldn't that give the first value if the key colum is ordered alphabetically?
Feb 4 '08 #5
amitpatel66
2,367 Expert 2GB
Wouldn't that give the first value if the key colum is ordered alphabetically?

ORDER BY is basically the way we want the data to be displayed in specific order.

If the value inserted is going to be INCREMENTAL, then MAX will fetch the correct result.
Feb 4 '08 #6
rajiv07
141 100+
Hi to all,

Actually My primary Key Has to be incremented by one With XTC String.Thats why i want to select last inserted record.Suppose my Last record is XTC10 the next record will be XTC11.

Regards
Rajivgandhi
Feb 5 '08 #7
amitpatel66
2,367 Expert 2GB
Hi to all,

Actually My primary Key Has to be incremented by one With XTC String.Thats why i want to select last inserted record.Suppose my Last record is XTC10 the next record will be XTC11.

Regards
Rajivgandhi
Then MAX(Primary Key Column) will get you the last inserted record.
Feb 5 '08 #8
rajiv07
141 100+
Hi to all
I have problem finding last inserted record.

my MfqNo (Primary key) column has a values which is incremented by 1 with XTC string for that i want to select the last inserted record But my query is Not working properly;

My MfqNo List

XTC1
XTC2
XTC3
XTC4
XTC5
XTC6
XTC7
XTC8
XTC9
XTC10
XTC11
XTC12
XTC13
XTC14

Expand|Select|Wrap|Line Numbers
  1. SELECT  max(mfqno) FROM hq_stock_details where mfqno LIKE 'XTC%';
When I execute this query it return the XTC9 record but i want select XTC14 which is inserted last;How do i do this.

Please Help on this

Thanks
Rajiv
Feb 23 '08 #9
ronverdonk
4,258 Expert 4TB
The strict char-value sort order in your case is:
Expand|Select|Wrap|Line Numbers
  1. XTC1
  2. XTC10
  3. XTC11
  4. XTC12
  5. XTC13
  6. XTC14
  7. XTC2
  8. XTC3
  9. XTC4
  10. XTC5
  11. XTC6
  12. XTC7
  13. XTC8
  14. XTC9
  15.  
so 9 is the highest, that is correct.

Ronald
Feb 23 '08 #10
mwasif
802 Expert 512MB
Hi rajiv07,

You can try this, but this will slow things down as table grow.
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM hq_stock_details WHERE MfqNo = (
  2.         SELECT CONCAT('XTC', MAX(CAST(REPLACE(MfqNo, 'XTC','') AS SIGNED))) FROM hq_stock_details
  3.         );
This is one approach, might be there are others :-)
Feb 23 '08 #11
ronverdonk
4,258 Expert 4TB
When the number part always starts at position 4, you can do this, i.e. just sorting the numeric part.
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM table by CAST(SUBSTR(column, 4) AS SIGNED);
Ronald
Feb 24 '08 #12
rajiv07
141 100+
Thanks to all Masters,
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM hq_stock_details WHERE MfqNo = (
  2. SELECT CONCAT('XTC', MAX(CAST(REPLACE(MfqNo, 'XTC','') AS SIGNED))) FROM hq_stock_details );
This query is working fine.My integer is not always starting with 4th character.The mfqno has different starting string and different integer position.

Regards
Rajiv.
Feb 25 '08 #13
mwasif
802 Expert 512MB
Glad to help you. Let us know if you need more help.
Feb 25 '08 #14

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

Similar topics

1
by: PT | last post by:
I got a problem. And thats..... First of all, I got these three tables. ------------------- ------------------ ---------------------- tblPerson tblPersonSoftware ...
1
by: Tony | last post by:
Thanks for writing back and don't laugh at what I am about to post I am new to this type of stuff....this is what I have tried and it isn't working(please note in the try section I was just trying...
14
by: alwayshouston | last post by:
Hi All! I am working on this very small database and I am confused in the designing a simple form. I only have three tables in the database. First Table: tblExpense Columns: ExpenseID ;...
11
by: Sandy | last post by:
Hello - Thought I was almost done with my project and then a back arrow button issue raised its ugly head. Once a user fills out a form and submits it (done via stored procedure into a Sql...
15
by: Jay | last post by:
I have a multi threaded VB.NET application (4 threads) that I use to send text messages to many, many employees via system.timer at a 5 second interval. Basically, I look in a SQL table (queue) to...
13
by: PinkBishop | last post by:
I am using VS 2005 with a formview control trying to insert a record to my access db. The data is submitted to the main table no problem, but I need to carry the catID to the bridge table...
11
by: Richard Maher | last post by:
Hi, I have read many of the copius entries on the subject of IE performance (or the lack thereof) when populating Select Lists. I don't mind the insert performance so much, (I get 100x120byte...
2
by: sheenaa | last post by:
Hi, I want to display the last recorded record in the database of SQL SERVER 2005. How can i display it with the select query in the grid view... The database contains the...
0
by: LanaR | last post by:
Hello, one sql statement is causing severe performance issue. The problem occurs only in UDB environment, the same statemnt on the mainframe is running fine. I have an explain output from the sql....
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: 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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.