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.
13 4399
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?? -
-
SETEC * from my_table WHERE ramstr = (SELECT MAX(ramstr) FROM my_table);
-
-
Try to take the MAX(primary key column) and check if it works?? -
-
SETEC * from my_table WHERE ramstr = (SELECT MAX(ramstr) FROM my_table);
-
-
It's working fine.Thank You for such a fast reply.
Regards
RajivGandhi
It's working fine.Thank You for such a fast reply.
Regards
RajivGandhi
You are Welcome :)
Amit
Try to take the MAX(primary key column) and check if it works?? -
-
SETEC * from my_table WHERE ramstr = (SELECT MAX(ramstr) FROM my_table);
-
-
Wouldn't that give the first value if the key colum is ordered alphabetically?
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.
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
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.
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 - 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
The strict char-value sort order in your case is: -
XTC1
-
XTC10
-
XTC11
-
XTC12
-
XTC13
-
XTC14
-
XTC2
-
XTC3
-
XTC4
-
XTC5
-
XTC6
-
XTC7
-
XTC8
-
XTC9
-
so 9 is the highest, that is correct.
Ronald
Hi rajiv07,
You can try this, but this will slow things down as table grow. - SELECT * FROM hq_stock_details WHERE MfqNo = (
-
SELECT CONCAT('XTC', MAX(CAST(REPLACE(MfqNo, 'XTC','') AS SIGNED))) FROM hq_stock_details
-
);
This is one approach, might be there are others :-)
When the number part always starts at position 4, you can do this, i.e. just sorting the numeric part. - SELECT * FROM table by CAST(SUBSTR(column, 4) AS SIGNED);
Ronald
Thanks to all Masters, - SELECT * FROM hq_stock_details WHERE MfqNo = (
-
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.
Glad to help you. Let us know if you need more help.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: PT |
last post by:
I got a problem. And thats.....
First of all, I got these three tables.
------------------- ------------------ ----------------------
tblPerson tblPersonSoftware ...
|
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...
|
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 ;...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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....
|
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,...
|
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$) {
}
...
|
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...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
| |