Finding the oldest record
I am trying to write a query that finds the oldest book in a libary and displays its location and book name. its returning with the wrong output so far
insert into OLDESTBOOK(LOCATION, NAME)
select
l.location, b.book_name
from
libary l, books b
where exists
select
Min(published_date), s.shelve_id, l.location_id
from
books b, shelve s, libary l
where
s.shelve_id = l.location_id
and
s.book_id = b.book_id
)
Yes, sorry, it should have been 'and' and not 'where'.
If you're getting multiple rows back, that mean that there are multiple books with the same oldest date, provided that your JOINs are correct. Are you getting different locations and book names in the multiple rows?
Edited by: SeánMacGC on Jul 23, 2009 3:33 AM
Another way to get the oldest would be:
SELECT Location, Book_Name,
FROM (
select l.location, b.book_name,
RANK() OVER (ORDER BY published_date) rnk
from books b, shelve s, libary l
where s.shelve_id = l.location_id
and s.book_id = b.book_id)
WHERE rnk <= 1;But again, if there are multiple locations and books with the same mininum published date, you'll get more than one record back.
Similar Messages
-
How to find the longest record in a table?
Hello,
Is there a function to find the longest record in a table? Or is there a data dictionary that would tell you which record contains the longest data?
I have a table with five columns and one million records. I want to find the record (5 columns combined) with the longest data. Thank you.Dear watson2000!
The function "VSIZE" tells you the number of bytes in the internal representation of a column which means the size of a value within a column. An example of vsize can be found here:
[http://www.adp-gmbh.ch/ora/sql/vsize.html]
So I think you should try it with this query to get the size of the longest record:
SELECT MAX(VSIZE(column1)) +
MAX(VSIZE(column2)) +
MAX(VSIZE(column3)) +
MAX(VSIZE(column4)) +
MAX(VSIZE(column5)) AS "Maximum Row"
FROM your_table;To identify the longest record try like this:
SELECT rowid
FROM your_table
GROUP BY rowid
HAVING (MAX(VSIZE(column1)) +
MAX(VSIZE(column2)) +
MAX(VSIZE(column3)) +
MAX(VSIZE(column4)) +
MAX(VSIZE(column5))) = (SELECT MAX(VSIZE(column1)) +
MAX(VSIZE(column2)) +
MAX(VSIZE(column3)) +
MAX(VSIZE(column4)) +
MAX(VSIZE(column5))
FROM your_table;)I hope that these two queries could be of help to you.
yours sincerely
Florian W.
Edited by: Florian W. on 23.04.2009 20:53 -
Any option is there to find the error record in loop for huge amount of rec
Hi Guru's,
In our production system we got a error. While debugging we found one of our loop getting 1 lakh records. One of the record from the internal table having some wrong values because of that its giving a error message. But we are not getting any proper message.
Now our problem is its very difficult to debug all the records one by one. Even its not possible to give Watchpoint. bze in what situations its giving this error that also not predictable. So how to find the error record?
Kindly suggest.
AnanadhanNeed a lot more info.
To start with is this CR Designer or some other product?
I suspect it's classic SAP products like Business One etc., if so please mark as answered and post your question int the correct forum.
Thank you
Don -
Finding the oldest file in a directory
I have a log directory that can have a lot of files in it. How can easily find the oldest file out of a large group of files in the directory so that I can delete it. The file name is of the form xxxx.*
I believe I can use a filter to get a list of files in the directory eith file name xxxx.* and then go through the list one by one and check the time stamp of the file and keep the name of the oldest one I find. Is there an easier way to just have these files ordered by modification date in acending order?check the File class docs. There is a method called lastModified() you can write some simple code that can keep track of the file with the oldest date.
-
To find the last record in cursor
hi
DECLARE
vCounter NUMBER;
-- Other variables...
BEGIN
vCounter:=0;
FOR .. IN cursor LOOP
IF vCounter=0 THEN
-- Here open file...
-- Here write one time data...
END IF;
-- Here write cursor data...
vCounter:=1;
END LOOP;
END;
hi all i am using above code to find the first record.
if vCounter =1 means its first record.
Now my question is how to find out the 'n'th record(last record).
please help me.
Thanks..user13329002 wrote:
hi
DECLARE
vCounter NUMBER;
-- Other variables...
BEGIN
vCounter:=0;
FOR .. IN cursor LOOP
IF vCounter=0 THEN
-- Here open file...
-- Here write one time data...
END IF;
-- Here write cursor data...
vCounter:=1;
END LOOP;
END;
hi all i am using above code to find the first record.
if vCounter =1 means its first record.
Now my question is how to find out the 'n'th record(last record).
please help me.
Thanks..create a record type variable to store last record;
assign the fetch data to that variable
and when u exit from the loop ,the variable will have the last records value
since you are using cursor for loop , it will Implicitly open, fetch, exit, and close occur to cursor.
eg:-
DECLARE
type cur_type is record of yourcursorname%type;
rec_cur_type cur_type;
vCounter NUMBER;
-- Other variables...
BEGIN
vCounter:=0;
FOR .. IN cursor LOOP
IF vCounter=0 THEN
-- Here open file...
-- Here write one time data...
END IF;
-- Here write cursor data...
assign your fetched record from cursor to rec_cur_type
vCounter:=1;
END LOOP;
END; -
How to find the unmatched records between the two tables?
We have to tables in SQL Server database.
But unable to find the unmatched record betwwen these two tables.
There 12 records are unmatched. But unable to get those records.
I am using the below sql:
select c1,c2,c3,c4,c5,c6 from Table1
except select c1,c2,c3,c4,c5,c6 from Table2
Please help. Thanks in advance.Hi knra,
Please try the following codes:
select c1,c2,c3,c4,c5,c6 from Table1 t1
where not exists
(select * from Table2 t2
where t1.c1= t2.c1
and t1.c2= t2.c2
and t1.c3= t2.c3
and t1.c4= t2.c4
and t1.c5= t2.c5
and t1.c6= t2.c6)
Best Regards,
Allen Li
Allen Li
TechNet Community Support
This is what I would've said, but it would make life much easier for you if you have a reference or ID for each entry, this is why we use keys. -
My ipod says it cannot find the pairing record how can I fix this
When I try to connect my ipod to iTunes it says that it cannot find the pairing record.
How do I fix this?Try here.
pairing record ?: Apple Support Communities
pairing record ?Also look at the previous discussions on the right side of this page under the heading "More Like This". -
How to find the particular record in 1000's of workflow jobs are running
Hi,
In a data manager -> in workflow tab>IF a record is in CHECK-OUT MODE there are 1000's of jobs are running in that workflow tab. Can anyone tell me how to find that particular record in that workflow jobs.
Can anyone show me the difference in getting a record in 5.5 and 7.1Hello COTI
Unfortunatly, SAP MDM doesn't have good ability for WF search.
All WF clarify by it's status (unlaunched, avialable, Received, complited, error etc.)
For each WF SAP MDM assing unique Job ID and this id will be shown in Job ID field in Data Manager WF Tab.
You can change WF list order by all WF fields like as Job ID, Step, User, Start etc. and try to find your's WF.
You can use Java API - this is one of the best solution for WF management and WF mass upload (for example)
Regards
Kanstantsin Chernichenka -
To find the duplicate record in internal table
Hi,
i have a requirement to fine the duplicate record with 3 fields.
i am getting a flat file with 15 fields .
i need to check the duplaicate records of 3 fields . if i get any 2nd same record of 3 fields , the records will go to other internal table.
for ex :
1. aaa bbb ccc ddd eee fff ggg hhh
2. aaa bbb ccf dde edd ffg ggh hhj
3. aaa bbb cce ddd ees ffh ggu hhk
in that 1st record and 3rd record are same (aaa bbb ddd)
i need to find 3rd record
please help me
regrards
srinivasuhi,
itab2[] = itab1[].
sort itab1 by f1 f2 f3.
sort itab2 by f1 f2 f3.
delete itab2 index 1. "to delete the first record in itab2.
loop at itab1 into ws_itab1.
loop at itab2 into ws_itab2.
if ws_itab1-f1 = ws_itab2-f1 and
ws_itab1-f2 = ws_itab2-f2 and
ws_itab1-f3 = ws_itab2-f3.
ws_itab3 = ws_itab2.
append ws_itab3 into itab3. "Third internal table.
endif.
endloop.
delete itab2 index 1.
endloop.
ITAB3 will have all the duplicate records.
Regards,
Subramanian -
Oracle 10g - To find the corresponding record for a certain row
Hi all,
The scenario is like this - Suppose I've got a table with 100+ columns. For a certain row inside, I need to find its corresponding record which is in the same table. The way how I define "corresponding" here is - these two rows should be identical in all attributes but only different in one column, say "id" (primary key).
So how could I achieve this? What I can think of is to fetch all columns of the first row into some pre-defined variables, then use a cursor to loop the table and match the values of the columns of each row to those variables. But given that we've got 100+ rows in the table, this solution doesn't look practical?
Any advises are greatly appreciated. Thanks.something to play with as Solomon suggested (use some other string aggregation technique if you're not 11g yet)
you'll have to adjust the column_list accordingly
select 'select ' || column_list ||
' from ' || :table_name ||
' group by ' || column_list ||
' having count(*) > 1' the_sql
from (select listagg(column_name,',') within group (order by column_id) column_list
from user_tab_cols
where table_name = :table_name
)Regards
Etbin
Edited by: Etbin on 25.12.2011 16:53
Sorry, I'd better leave the forum: the title says you're 10g :(
Providing a link for replacing listagg: http://www.sqlsnippets.com/en/topic-11787.html -
Query to find the latest record with respect to the current status
Dear gurus
I have the following data in a table
Customernum
bkcode
reqtdate
Prevstat
currstat
The data will be like this
CustomerNum bkcode reqdate prevstat currstat
5900 1 03-Aug-12 0 1
5900 1 06-Aug-12 1 0
5900 5 22-Jun-12 0 1
If a customer has an issue to solved, a record is added with bkcode , register date and currstat will be 1
If the issue is resolved for the bookingcode,a new record is added, the currentstatus will become 0. and prev stat will show 1. Row no 1 and 2 reflects this case
If this table is queried for finding the unresolved issues. the output should be only the Last row of the above example. since issue with bookingcode 1 has been resolved
I have trying hard to get this thing confused what to use Lead or Max
Kindly guide meHi,
one way here:
WITH mytable(CustomerNum, bkcode, reqdate, prevstat, currstat)
AS
SELECT 5900, 1, TO_DATE('03-Aug-12', 'DD-Mon-YY'), 0, 1 FROM DUAL UNION ALL
SELECT 5900, 1, TO_DATE('06-Aug-12', 'DD-Mon-YY'), 1, 0 FROM DUAL UNION ALL
SELECT 5900, 5, TO_DATE('22-Jun-12', 'DD-Mon-YY'), 0, 1 FROM DUAL
SELECT CustomerNum, bkcode, reqdate, prevstat, currstat
FROM (SELECT a.*
, ROW_NUMBER() OVER (PARTITION BY CustomerNum, bkcode
ORDER BY reqdate DESC) AS rn
FROM mytable a
WHERE rn=1
AND currstat=1;
CUSTOMERNUM BKCODE REQDATE PREVSTAT CURRSTAT
5900 5 22-JUN-12 0 1Regards.
Al
Edited by: Alberto Faenza on Dec 18, 2012 5:23 PM
Changed again!! Previous logic was wrong -
How to find the last records of the table in adventure work db
hi all,
i want to find out " how to receive a last records of the table (eg: person.emailaddress ) in sql 2008 and 2005"
ThanksIf you are looking for the latest record( the one which got inserted/modified last) then use this query
select top 1 * from person.emailaddress
Order by ModifiedDate desc
Satheesh
My Blog |
How to ask questions in technical forum -
Why the oldest recorded track get recorded again when making new track?
1. I play my guitar and record it (track1)
2. I play track1 and recording my vocal
3. The track1 get recorded again on my vocal track
How to set off that? So i dont have double sound of the oldest track on the new trackKaibe008 wrote:
3. The track1 get recorded again on my vocal track
How to set off that?
use headphones -
How to find the next record b4 the loop end
hai all
i have suffering big problem... i have the internal table call IT_ITAB.. so i can go to the rerecord by record using loop comand..
example:
loop at IT_ITAB.
1.record1
2.record2
3.record3
4.record4
endloop.
Allways end of loop go to next record...... my problem is before end of the loop i want to check the next record... how should i do it... please help me...
regard
nawaHi,
One approach u can follow is that copy the data of the internal table into another one.
Maintain an integer type variable which will contain the index value of the loop. Check the entry from other table.
e.g.
Loop at itab1.
ctr = sy-tabix + 1.
read itab2 index ctr.
This way u can check the next record while u r still in loop.
Hope it helps.
Regards,
Himanshu -
How to the find the Delete records/Statement used in Oracle 10g database?
Hi all,
I am Using Oracle 10g Database release 2 on Windows 2003 Server Enterprise Edition... Last week One of my user has deleted important records from my database,i need to find who did this... is there any way to find out ...Please Advice me ....One More thing i have not enabled the Auditing features in My database .....
Thank You
ShanRajesh Lathwal wrote:
Use log miner ..
Regards
RajeshEven with that, if he wants to know WHO, he will have to have previously enabled extended logging ....
Maybe you are looking for
-
Help...how do I download my photos from an external hard drive into iphoto
Help, can someone tell me how to download my photos from an external hard drive that was a previous dell computer with windows.. we ditched the dell and got the imac... but I'm lost....please help.
-
Change the already installed Win 8.1 BIOS mode from Legacy to UEFI
Hey, It seems that my Windows 8.1 is installed in BIOS mode: Legacy as "msinfo32.exe" shows. I can boot into it with no issue, but when I go to my laptop's BIOS settings and change the mode back to UEFI, it gives me an error "Operating system not fou
-
Hello, I want to deploy the JDBC driver for Oracle databases as described in OSS 1138877 on a brand-new PI7.1 (SP06 Stack) installation. Unfortunately, I can't find com.sap.aii.adapter.lib.sda on the system, so I can't add the ojdbc14.jar file and de
-
GridBagLayout: JInternalFrames and internal JDesktopPanes?
What I want: A JToolbar a the top of my main JFrame and a JPanel (status bar) at the bottom of my frame that stretches/shrinks with the screen. AND JInternalFrames in the center area (the number is arbitrary and the position is -- for now -- arbitrar
-
Radeon 128MB 9600XT DDR vs Geforce Fx5700-TD128 8x AGP 128MB
could u tell me what graphicsd card would give me the best perormacnce from my current pc configuration Radeon 128MB 9600XT DDR or the Geforce Fx5700-TD128 8x AGP 128MB