get the last record
What is the best way to get the last record in a table?... in addition to select * from tbl by id Desc... & then set = 1 maxrow in cfoutput.
I want a quick way.
I tried "Max (id), columns, but not worked.
If I ' Max (id) as V ' & then turn around and make another request for ' where id = #V # "to get the rest of the record, there's more action.
Quote:
Posted by: paross1
One way...SELECT all your columns
From your_table
WHERE your_engagement_appid = (SELECT MAX (your_id)
From your_table)Phil
Thank you guys. It worked great.
I also tried the front joined query where the... I would have thought that.
Thank you!
Tags: ColdFusion
Similar Questions
-
How to get the last records of a Table
Hey Geeks,
I have this 'conflict '.
I need to get the 'current balance' for each account, the newest "current_Balance".
The table looks like this
ACCOUNT_ID BUSINESS_TRANSACTION_ID CURRENT_BALANCE TRANSACTION_AMOUNT TRANSACTION_DATE 1 062 570 238 043 517 51'022 -20'000 31.03.2014 17:49:00.808000 1 062 570 238 042 407 71'022 -20'000 31.03.2014 17:33:55.666000 1 062 570 238 042 368 91'022 -26'000 31.03.2014 17:33:20.067000 1 062 570 238 041 273 117'022 -50,000 31.03.2014 17:18:25.189000 1 062 570 238 041 174 167'022 -10,000 31.03.2014 17:16:59.361000 1 062 570 238 038 702 177'022 -2'500 31.03.2014 16:44:58.332000 5 607 555 238 046 713 1'026 -28'500 31.03.2014 18:35:16.212000 5 607 555 238 040 592 29'526 -100,000 31.03.2014 17:10:15.474000 I need this result:
ACCOUNT_ID CURRENT_BALANCE
5 607 555 1'026
1 062 570 51'022
How we handle this?
Thxs for your help
Ineffective :-)
SELECT Account_id
MAX (current_balance) KEEP (DENSE_RANK LAST ORDER BY transaction_date) current_balance
MAX (business_transaction_id) KEEP (DENSE_RANK LAST ORDER BY transaction_date) business_transaction_id
Of account_balances
GROUP BY account_id
Concerning
Marcus
-
How to get the last row and the sum of all columns in a query
Hello
is there a way to get the last record for a column and the sum of all the Archives to another column in the same query.
Best regards
You must set your needs correctly volunteers to help here...
Your data are not good enough to bring you a precise solution. Purpose, you do not have a column, which draws a distinction between the first and the last entry.
The solution becomes easy based on your design.
I introduced a grouping called 'id' column and a time column called 'time_of_insert' (only this way you can say with confidence that you can differentiate between the first and last (also a foolproof solution) - you can possibly use sequence (instead of date but if you say that you can insert two lines at the same time) ((and then likely sequence would be a better choice to differentiate instead of a timestamp field) etc...)
With your sample data, something like this can be done to get the desired results.
-----------------------------------------------------------------------------------------------------------------------
WITH dataset AS
(SELECT 1 id, 10 used, 8 remain, systimestamp + 1/24 time_of_insert FROM DUAL
UNION ALL
SELECT the 1 id, 1, 7, systimestamp + 2/24 FROM DUAL
UNION ALL
SELECT the id 1, 2, 5, systimestamp + 3/24 FROM DUAL
UNION ALL
SELECT 1 id, 1, 0, systimestamp + 4/24 FROM DUAL
UNION ALL
SELECT 1 id, 0, 0, systimestamp + 5/24 FROM DUAL
UNION ALL
SELECT the 1 id, 1, 4, systimestamp + 6/24 FROM DUAL)
SELECT *.
(SELECT SUM (used) ON sum_all)
FIRST_VALUE (stay)
COURSES (PARTITION BY id ORDER BY time_of_insert DESC)
last_row
Of THE dataset)
WHERE ROWNUM = 1;
Output:
------------------------
SUM_ALL LAST_ROW
------------------------------
15 4
See you soon,.
Manik.
-
How to get the particular record last
Hello
I want the query because if a particular record available when enter as a last record.
Ex,
name
----------
s
t
h
but t is always the last record. How to get?
Thank you
Alphadi.Welcome to the forum.
Do you mean you want to 'h' to appear as the last record?
Try:SQL> -- generating sample data: SQL> with t as ( 2 select 'h' name from dual union 3 select 's' from dual union 4 select 't' from dual 5 ) 6 -- 7 -- actual query: 8 -- 9 select name 10 from t 11 order by case 12 when name = 'h' then 2 13 else 1 14 end; NAME -------------------- s t h 3 rows selected.
-
Get the last disc based on the date
Version of database
Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64 bit Production
PL/SQL Release 9.2.0.8.0 - Production
CORE Production 9.2.0.8.0
AMT for HP - UX: 9.2.0.8.0 - Production Version
NLSRTL Version 9.2.0.8.0 - Production
data and model table
CREATE TABLE EXAMPLE
(
UNIT_ID1 VARCHAR2 (15 BYTE) NOT NULL,
COLL_DATE1 DAY,
ATTRIB_CODE1 VARCHAR2 (4 BYTE) NOT NULL,
UNIT_ID2 VARCHAR2 (15 BYTE),
COLL_DATE2 DAY,
ATTRIB_CODE2 VARCHAR2 (4 BYTE),
DATE OF AUDIT_INSERT_DATS NOT NULL
)
Insert into SAMPLE
(UNIT_ID1, COLL_DATE1, ATTRIB_CODE1, UNIT_ID2, COLL_DATE2,
ATTRIB_CODE2, AUDIT_INSERT_DATS)
Values
('W039712008646', TO_DATE (OCTOBER 8, 2012 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'DP', 'W039712008646', TO_DATE (OCTOBER 8, 2012 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'),)
'PP', TO_DATE (OCTOBER 9, 2012 11:10:56 "," MM/DD/YYYY HH24:MI:SS'));)
Insert into SAMPLE
(UNIT_ID1, COLL_DATE1, ATTRIB_CODE1, UNIT_ID2, COLL_DATE2,
ATTRIB_CODE2, AUDIT_INSERT_DATS)
Values
('W039712008646', TO_DATE (OCTOBER 8, 2012 00:00:00 "," MM/DD/YYYY HH24:MI:SS'), 'DP', NULL, NULL,)
'DP', TO_DATE (OCTOBER 9, 2012 11:11:02 "," MM/DD/YYYY HH24:MI:SS'));)
Insert into SAMPLE
(UNIT_ID1, COLL_DATE1, ATTRIB_CODE1, UNIT_ID2, COLL_DATE2,
ATTRIB_CODE2, AUDIT_INSERT_DATS)
Values
('W039712008647', TO_DATE (OCTOBER 8, 2012 00:00:00 "," MM/DD/YYYY HH24:MI:SS'), 'DP', NULL, NULL,)
'DP', TO_DATE (OCTOBER 9, 2012 11:15:18 ',' DD/MM/YYYY HH24:MI:SS'));)
Insert into SAMPLE
(UNIT_ID1, COLL_DATE1, ATTRIB_CODE1, UNIT_ID2, COLL_DATE2,
ATTRIB_CODE2, AUDIT_INSERT_DATS)
Values
('W039712008649', TO_DATE (OCTOBER 8, 2012 00:00:00 "," MM/DD/YYYY HH24:MI:SS'), 'TP', NULL, NULL,)
'TP', TO_DATE (OCTOBER 9, 2012 11:15:39 ',' DD/MM/YYYY HH24:MI:SS'));)
Insert into SAMPLE
(UNIT_ID1, COLL_DATE1, ATTRIB_CODE1, UNIT_ID2, COLL_DATE2,
ATTRIB_CODE2, AUDIT_INSERT_DATS)
Values
('W039712008650', TO_DATE (OCTOBER 8, 2012 00:00:00 "," MM/DD/YYYY HH24:MI:SS'), 'RD', NULL, NULL,)
'RD', TO_DATE (OCTOBER 9, 2012 11:16:10 ',' DD/MM/YYYY HH24:MI:SS'));)
Insert into SAMPLE
(UNIT_ID1, COLL_DATE1, ATTRIB_CODE1, UNIT_ID2, COLL_DATE2,
ATTRIB_CODE2, AUDIT_INSERT_DATS)
Values
('W039712008653', TO_DATE (OCTOBER 8, 2012 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'CX', NULL, NULL,)
'CX', TO_DATE (OCTOBER 9, 2012 11:17:23 ',' DD/MM/YYYY HH24:MI:SS'));)
COMMIT;
-----------------------
unit_id W039712008646 has two records. I need a query to get the last disk based on audit_insert_dats. Any help is appreciated.
I tried to use max (audit_insert_dats) but not able to get a recorduser_anumoses wrote:
unit_id W039712008646 has two records. I need a query to get the last disk based on audit_insert_dats.You can use the ROW_NUMBER() analytic function
SQL> select * 2 from 3 (select a.*, 4 row_number() over(partition by UNIT_ID1 order by AUDIT_INSERT_DATS desc) rn 5 from sample a) 6 where rn = 1; UNIT_ID1 COLL_DATE ATTR UNIT_ID2 COLL_DATE ATTR AUDIT_INS RN --------------- --------- ---- --------------- --------- ---- --------- ---------- W039712008646 08-OCT-12 DP DP 09-OCT-12 1 W039712008647 08-OCT-12 DP DP 09-OCT-12 1 W039712008649 08-OCT-12 TP TP 09-OCT-12 1 W039712008650 08-OCT-12 RD RD 09-OCT-12 1 W039712008653 08-OCT-12 CX CX 09-OCT-12 1
-
remove the last record from the plsql table
Under certain conditions, I need to remove the last record from i_CustomerLoopTYPE r_LOOPElement IS RECORD (TermID NUMBER ); TYPE t_LOOPType IS TABLE OF r_LOOPElement INDEX BY BINARY_INTEGER; i_CustomerLoop t_LOOPType ; i_CustomerLoop(1).TermID=1; i_CustomerLoop(2).TermID=2; i_CustomerLoop(3).TermID=3;
whichi s the best way to do it. because I sometimes get duplicates for TermID in this plsql table.Hello
See [removing items from Collection (DELETE method) | http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28370/collections.htm#CJAFGFIG]
Kind regards
-
Format the first and the last record of query result
Hello
I have the following query
< tt > select 1 seq, "This is the first record" data from dual union of all the
Select 2, 'Data ' | tNom tab Union all
Select 3, "It was last last record" double
order by 1 < /tt >
When I have the coil this summary to a listfile with col seq noprint option I get:
This is the first record
Data MLA_ACCESS_LIST
Data MLA_APPLICATIONS
Data MLA_VPD_PCK
Data MLA_VPD_TABLES
It was the last last record
But I want to:
It's first record MLA_ACCESS_LIST
Data MLA_APPLICATIONS
Data MLA_VPD_PCK
MLA_VPD_TABLES it was save finally last record
I tried with 1 statement with the use of lead and lag, because first and last record stand the other result record. But I get ORA-30484: lack of specification of the window for this function
Is this possible with 1 statement or am I've sentenced to modify the results by myself?
Thank you AukeSelect row_number() case above (tNom control)
When 1 then 'it's the first record
end | tNom |
-case row_number() over (order by desc tNom)
When 1 then 'it was the last record. "
end
tab
order by tNomHTH
-
How to get the last message received in the Inbox?
Currently I am using the following code to the list of messages in the Inbox.
Folder[] folders = store.list(Folder.INBOX);Folder inbox = folders[0];Message[] msgs = inbox.getMessages();
But, how could I do the last message that was received in my inbox at the moment?
I have a lot of unread messages in my Inbox and I can even receive the same message from sender twice at the same time, but I need access to the last message you received.
Thank you
As I have a implements FolderListener, I need to get the last message of FolderEvent object. But, I tried to access the last Inbox message, which will not always be there!
Thanks Deepesh
-
How to get the last date of 3 days for the current month?
Hello. Guy
How to get the last date of 3 days for the current month?
MY OUTPUT WOULD LOOK LIKE THIS
JANUARY 29, 2016
JANUARY 30, 2016
JANUARY 31, 2016
GUYS HELP ME / / /...
SQL > select last_day (sysdate) - level + 1 double connect by level<= 3="" order="" by="">=>
LAST_DAY)
---------
29 JANUARY 16
30 JANUARY 16
31 JANUARY 16
-
Select the last record of each month
Hello
to select the last docnumber and qty of every month
Structure
Name Null? Type
------------------------------- -------- ----
PRODUCTCODE NUMBER
NUMBER NUMBER
DATE OF PLANFORMONTH
NUMBER OF CLEXPECTEDQTY
NUMBER OF CLCONFIRMQTY
NUMBER OF CLFGBUFFERQTY
NUMBER OF CLTOTPRINTBUFFER
in this select query if I take the sum he required all records where, as I want the last record of each month
SELECT productcode docnumber MAX (Number), planformonth, SUM (clexpectedqty) clexpectedqty (planformonth) MAX.
SUM (clconfirmqty) clconfirmqty, SUM (clfgbufferqty) clfgbufferqty, cltotprintbuffer OF FGSALESPLAN of the SUM (cltotprintbuffer)
GROUP BY productcode, (planformonth)
Sandy
Hello
Thanks its working now the code is written as below:
SELECT * FROM
(SELECT
e.*,
ROW_NUMBER() OVER (partition by PRODUCTCODE by DOCNUMBER DESC order) r
Of
E FGSALESPLAN)
WHERE r = 1 AND
entryvalid = 'Y '.
order by Number
Sandy
-
How to get the last business day of the previous month?
Hi all
We need the user as below,
If the user select 18 June 2015 ' quick dashboard as the input value, and then they want to see last month last day of work (business date: 29-may-2015) amount in report, if you have an idea please share with us.thanks
Note:
use under request we can able to get the last day of the previous month, we want to for the last business day of the last month, based on the date of entry of the user?
TIMESTAMPADD (SQL_TSI_DAY,-(1), TIMESTAMPADD (SQL_TSI_DAY, DAYOFMONTH ("DIM_TIME". ("" DataDate ") *-(1) + 1,"DIM_TIME ". (("" DataDate "))
Thank you
Deva
Try this,
case when Dayofweek (timestampadd (sql_tsi_day, Dayofmonth(Date '2015-06-15') *-1, Date ' 2015-06-15')) = 1 then timestampadd (sql_tsi_day, (Dayofmonth(Date '2015-06-15') *-1)-2, Date '' 2015-06-15) when Dayofweek (timestampadd (sql_tsi_day, Dayofmonth(Date '2015-06-15') *-1, Date ' 2015-06-15')) = 7 then timestampadd (sql_tsi_day, Dayofmonth(Date '2015-06-15') *-1-1, Date '' 2015-06-15) another timestampadd (sql_tsi_day, Dayofmonth(Date '2015-06-15') *-1, Date ' 2015-06-15') end
As Ftsiot said in this post, it will work only to exclude the sat and Sun. Another one if you want to exclude regional holiday, you may need a calendar in DB table.
Thank you
AJ
-
I have been using Photoshop CS5 for some time for photos products (jewelry). What are my best options to get the last Photoshop.
Hi michaelb.
You can subscribe to Plan photography for $9.99 a month, which will give the latest version of Photoshop CC 2015, CC 2015 Lightroom and Adobe Bridge.
Lightroom and Photoshop | Plan of cloud of Adobe's creative photography
Kind regards
Mohit
-
How to get the last day of the weekend rather than a month
Hi all
Is the request appropriate and preferable to use to get the last business day of the month below?
SELECT to_date('13.08.2014','dd.mm.yyyy') + MAX(RNUM) LastDay(nonweekend) FROM (SELECT ROWNUM RNUM FROM ALL_OBJECTS where rownum <=31) WHERE ROWNUM <= 31 ANd TO_CHAR(to_date('13.08.2014','dd.mm.yyyy') + RNUM, 'DY','NLS_DATE_LANGUAGE=ENGLISH' ) NOT IN ('SAT' , 'SUN') and to_date('13.08.2014','dd.mm.yyyy') + RNUM <= last_day(to_date('13.08.2014','dd.mm.yyyy'))
I have to use this motion for production.
East - recommended to use?
You can change your query this way:
WITH t AS (SELECT trunc (to_date ('& calc_date', 'dd.mm.yyyy'), 'mm') + level - 1 calc_date)
OF THE DOUBLE
CONNECT BY LEVEL<= last_day(to_date('&calc_date',="" 'dd.mm.yyyy'))="" -="" trunc(to_date('&calc_date',="" 'dd.mm.yyyy'),="" 'mm')="" +="">=>
)
Select max (calc_date)
t
where to_char (calc_date, 'DY', 'NLS_DATE_LANGUAGE = ENGLISH') NOT IN ("SAT", "Sun");
-
How to get the last day of a month for every 2 months for a given period?
Hello
Can is it some please let me know how to get the last day, last day of the week, the weekend last day, last Monday, one month for every 2 months for a given period?
Thanks in advance.
Try the below
SELECT LAST_DAY (ADD_MONTHS (TRUNC(startdate,'MM'), ((LEVEL*2)-2))) lastday.
BOX WHEN TO_CHAR (LAST_DAY (ADD_MONTHS (TRUNC(startdate,'MM'), ((LEVEL*2)-2))), 'DY') = 'SAT '.
SO LAST_DAY (ADD_MONTHS (TRUNC(startdate,'MM'), ((LEVEL*2)-2)))-1
WHERE TO_CHAR (LAST_DAY (ADD_MONTHS (TRUNC(startdate,'MM'), ((LEVEL*2)-2))), 'DY') = 'Sun '.
THEN LAST_DAY (ADD_MONTHS (TRUNC(startdate,'MM'), ((LEVEL*2)-2)))-2
Of OTHER LAST_DAY (ADD_MONTHS (TRUNC(startdate,'MM'), ((LEVEL*2)-2)))
END as lastweekday,
BOX WHEN TO_CHAR (LAST_DAY (ADD_MONTHS (TRUNC(startdate,'MM'), ((LEVEL*2)-2))), 'DY') IN ('Sam', 'SUN')
THEN LAST_DAY (ADD_MONTHS (TRUNC(startdate,'MM'), ((LEVEL*2)-2)))
Of OTHER LAST_DAY (ADD_MONTHS (TRUNC(startdate,'MM'), ((LEVEL*2)-2)))
-(TO_NUMBER (TO_CHAR (LAST_DAY (ADD_MONTHS (TRUNC(startdate,'MM'), ((LEVEL*2)-2))),' from)) - 1).
END as lastweekendday,
BOX WHEN TO_CHAR (LAST_DAY (ADD_MONTHS (TRUNC(startdate,'MM'), ((LEVEL*2)-2))), 'DY') = 'MY
THEN LAST_DAY (ADD_MONTHS (TRUNC(startdate,'MM'), ((LEVEL*2)-2)))
Of OTHER NEXT_DAY (LAST_DAY (ADD_MONTHS (TRUNC(startdate,'MM'), ((LEVEL*2)-2))), "LUN")-7
END AS lastmonday
FROM (SELECT SYSDATE startdate,
SYSDATE + 300 enddate
THE DOUBLE)
CONNECT BY LEVEL<=>=>
-
tried to get the last update. Update froze at 2%. Help
Tried to get the last update. It froze at 2%. Any help much appreciated.
Hello
Go close before the creative Cloud Desktop Application and also all related processes for the same if it's windows, the Manager of tasks and activity monitor if it's the Mac.
Very close to the AAMUpdater, Core Sync and IPCBroke process.
So go ahead and uninstall the Cloud Desktop creative Application from the link below.
Using creative cloud | Uninstall the creative cloud desktop application
and install the above from the link below.
https://creative.Adobe.com/products/creative-cloud
Concerning
Maansee
Maybe you are looking for
-
Read file measure to XY Chart of waveform
Something pretty simple that gives me a hell of a time right now. I have a .lvm here who was rescued from an acquisition of data and has a column of numbers from 0.0000 - 27.0000 to very small no. The next column is the amplitude of the signal at the
-
When you try to change my password, I accidentally deleted my admin account
I tried to change my password, and I accidently deleted my accaund administrator
-
Put the new upgrade of Windows 10 on my 500 gig SSD and make the main drive (C :)
Original title: Windows 10 You want to install (upgrade) new Windows 7 Pro 64) Windows 10. No problem. Here's my question and need help. I want to put the upgrade of Windows new 10 on my 500 gig SSD and make the main drive (C :) Just got new PC an
-
Error 80073701 when you install Windows 7 Service Pack 1
I met an error code 80073701 when you install Windows 7 Service Pack 1 and it could not be installed in my PC. So, what should I do to solve this problem. Thank you very much!
-
Help me.I turn on blackberry protect service location and switch. After BlackBerry ID and password, log in. But my camera is not associated with BlackBerry Protect. Help me