Getting the first record
I have a table containing infor about employees promotion details.Problem is that the table was so badly designed that the only way for me to know the first promotion that an employee got in that year was the way it was inserted.Hence below for Manohar ,91 was the first promotion in the year 2001 and
for Sanohar it is 81.
Wondering is there sql query throught which I can get hold of the first record that was inserted.
YEAR____EMPCODE_____NAME_______POSITION
2001______02_________Manohar________91
2001______02_________Manohar________01
2001______02_________Manohar________07
2001______03_________Sasohar________81
2001______03_________Sasohar________84
2001______03_________Sasohar________87
this migth be of help:
SQL> select rowid, year, empcode, name, position
2 from employees;
ROWID YEAR EM NAME PO
AAD8PAAAJAAAAzwAAA 2001 02 Manohar 91
AAD8PAAAJAAAAzwAAB 2001 02 Manohar 01
AAD8PAAAJAAAAzwAAC 2001 02 Manohar 07
AAD8PAAAJAAAAzwAAD 2001 03 Sasohar 81
AAD8PAAAJAAAAzwAAE 2001 03 Sasohar 84
AAD8PAAAJAAAAzwAAF 2001 03 Sasohar 87
6 rows selected.
Elapsed: 00:00:00.00
SQL> select emp.year, emp.empcode, emp.name, emp.position,
2 emp.promotion, rowid
3 from (select year, empcode, name, position,
4 rank() over (partition by empcode order by rowid) promotion
5 from employees) emp
6 /
YEAR EM NAME PO PROMOTION ROWID
2001 02 Manohar 91 1 AAD8PAAAJAAAAzwAAA
2001 02 Manohar 01 2 AAD8PAAAJAAAAzwAAB
2001 02 Manohar 07 3 AAD8PAAAJAAAAzwAAC
2001 03 Sasohar 81 1 AAD8PAAAJAAAAzwAAD
2001 03 Sasohar 84 2 AAD8PAAAJAAAAzwAAE
2001 03 Sasohar 87 3 AAD8PAAAJAAAAzwAAF
6 rows selected.
Elapsed: 00:00:00.00
SQL> note: you can use the rowid to identify which row has been inserted first. if this is something that you want to get the first row that was inserted.
Similar Messages
-
How to get the first and the last record of every month within a time range in sql
I am trying to get the first record and the last record of each and every month in a given date range using sql. I have a sample code
where i have just selected everything within the date range now i have to extract the first and the last records of each and every month.
SELECT PurOrderNum,
OrderDate
FROM Purchasing.PurOrder
WHERE OrderDate >= '2013-02-28'
AND OrderDate <= '2014-12-29'SELECT PurOrderNum,
OrderDate
FROM
SELECT PurOrderNum,
OrderDate,
MAX(OrderDate) OVER (PARTITION BY DATEDIFF(mm,0,OrderDate)) AS MaxDate,
MIN(OrderDate) OVER (PARTITION BY DATEDIFF(mm,0,OrderDate)) AS MinDate
FROM Purchasing.PurOrder
WHERE OrderDate >= '2013-02-28'
AND OrderDate <= '2014-12-29'
)t
WHERE OrderDate = MaxDate
OR OrderDate = MinDate
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My MSDN Page
My Personal Blog
My Facebook Page -
How to get the first and last record
Hai All
I have table called T1 and there are more than 8 lakhs records and i have a column called Timestamp so i need to get the first record value and time stampvalue and last record and time stamp value so that i can conclude that For Example
form 13 june to 15 june data are here
Kind Regards
SrikkanthMSomething like this can also indicate the first and last rows as you query...
SQL> select empno, ename, hiredate
2 ,case row_number() over (order by hiredate)
3 when 1 then 'First Row'
4 when count(*) over () then 'Last Row'
5 end as flag
6 from emp;
EMPNO ENAME HIREDATE FLAG
7369 SMITH 17/12/1980 00:00:00 First Row
7499 ALLEN 20/02/1981 00:00:00
7521 WARD 22/02/1981 00:00:00
7566 JONES 02/04/1981 00:00:00
7698 BLAKE 01/05/1981 00:00:00
7782 CLARK 09/06/1981 00:00:00
7844 TURNER 08/09/1981 00:00:00
7654 MARTIN 28/09/1981 00:00:00
7839 KING 17/11/1981 00:00:00
7900 JAMES 03/12/1981 00:00:00
7902 FORD 03/12/1981 00:00:00
7934 MILLER 23/01/1982 00:00:00
7788 SCOTT 19/04/1987 00:00:00
7876 ADAMS 23/05/1987 00:00:00 Last Row
14 rows selected.
SQL> -
Get the first item value of previous record in a multi record block
Hai,
I have a multi record block with four items.I should get the first item value of the previous record so that I can increment its value in the current record.
Thanks.........If you want a distinct value in each row or to be able to retrieve the records in the same order they were written then you should use a sequence.
If you want to retrieve the records in the same order they were created in the block then you will need a diffferent solution to the one you outline here since a user could enter a new record between two others.
I posted this a while back in response to someone who was using a sort_key item and resetting it for each row when a new record was inserted:
If you make the sort_key bigger then you have much more room to insert new rows in between existing rows without having to reset all the sort_keys.
Eg. you have rows with sort_keys of 129282000000000000 and 129283000000000000 (you can have more zeros if you want) and you want to insert a row in between. if you're using oracle forms then the user would have to click on the first of these rows and then do 'insert'. in your insert process you would store the sort keys of the current record and the one below, create a blank record in between and set the sort_key of that record to the average of the other two. you will be able to insert many new rows in between the original 2 before running out of space in the sort_key field.
the method above is not sufficient, there are some other cases to consider:
1) when the user is on the last record of the block then you will just create a new record with sort_key set to a greater number than the row before. you can have the sort_key defined as number(38) and to safely allow you to enter 1000 rows each new row would normally be 10E33 greater than the previous one.
2) when the user is entering the first record then just set the sort_key to 10E33.
3) on the off-chance that you do insert a great number of records and cannot insert another in between then you would need to alert the user, process the records so that the sort_keys are evenly spaced and requery the block. this processing could be scheduled nightly to make this eventuality even less likely.
4) make sure the user cannot run the default 'clear_record' procedure. this would break my method as well as yours!
James. -
Getting the first row for each group
Hi Everyone,
I have a query which returns a number of rows, all of which are valid. What I need to do is to get the first row for each group and work with those records.
For example ...
client flight startairport destairport stops
A fl123 LGW BKK 2
A fl124 LHR BKK 5
B fl432 LGW XYZ 7
B fl432 MAN ABC 8
.... etc.
I would need to return one row for Client A and one row for Client B (etc.) but find that I can't use the MIN function because it would return the MIN value for each column (i.e. mix up the rows). I also can use the rownum=1 because this would only return one row rather than one row per group (i.e. per client).
I have been investigating and most postings seem to say that it needs a second query to look up the first row for each grouping. This is a solution which would not really be practical because my query is already quite complex and incorporating duplicate subqueries would just make the whole thing much to cumbersome.
So what I really new is a "MIN by group" or a "TOP by group" or a "ROWNUM=1 by group" function.
Can anyone help me with this? I'm sure that there must be a command to handle this.
Regards and any thanks,
Alan Searle
Cologne, GermanySomething like this:
select *
from (
select table1.*
row_number() over (partition by col1, col2 order by col3, col4) rn
from table1
where rn = 1In the "partition by" clause you place what you normally would "group by".
In the "order by" clause you define which will have row_number = 1.
Edit:
PS. The [url http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/functions004.htm#i81407]docs have more examples on using analytical functions ;-)
Edited by: Kim Berg Hansen on Sep 16, 2011 10:46 AM -
I need to update specific records(of variable lengths) in a file. I can get the correct record but when I update it(add or change info), it overwrites part of the record following it. I am using labview 6.0. I need to be able to insert information into the middle of a file without disturbing the data before and after
It's hard to give more specifics without more detail, but in general you're going to need to read in the entire file, split it into three pieces (everything before the record of interest, the record itself, and everything after the record of interest), modify the record, reassemble the three pieces in proper order, and write the whole thing back to the file.Of course if the file is very large you might not want to actually implement it this way, but conceptually at least, this is what you are looking at.If this file some sort of proprietary format?Mike...PS: this type of issue is why I really like databases...
Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion
"... after all, He's not a tame lion..."
Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps -
Oracle Forms returns the first record in the database when performing query
Once in a while when we query for a record on a form, say by first name Tom, then it returns the first record in the database. Other times it return the Tom's record. It only happens once in a while and if you close the form and reopen it and requery for Tom, then it brings Tom's record.
Does anyone know the issue what could be happening. It just happens every now and then that it's hard to reproduce.
ORacle Forms 10GR2
ORacle Application Server 10.1.3
thanksthen it returns the first record in the databaseI'm not sure if i understand you correctly. Do you mean forms ignores the searc-condition you entered? I would check SYSTEM.LAST_QUERY at the moment this happens to check if the condition gets somehow lost.
-
How to get the previous record value in the current record plz help me...
In my sql how to get the previous record value...
in table i m having the field called Date i want find the difference b/w 2nd record date value with first record date... plz any one help me to know this i m waiting for ur reply....
Thanx in Advance
with regards
kotreshFirst of this not hte mysql or database forum so don;t repeate again.
to get diff between two date in mysql use date_format() to convert them to date if they r not date type
then use - (minus)to get diff. -
DB Adapter: Polling For New Records returns the First record multiple Times
I Polling for New or Chnaged Records against DB2 on iSeries. The DB Adapter returns the first record from the Table multiple Times. If the Table has 5 records it displays the first record 5 times. I am using BPEL 10.1.3.1 Can anyone help me with this.
Hi there,
please check out the DBAdapter trouble-shooting guide:
http://download-east.oracle.com/docs/cd/B31017_01/integrate.1013/b28994/app_trblshoot.htm#CIHFEHFA
I am copying an entry from there into here:
A.1.21 Some Queried Rows Appear Twice or Not at All in the Query Result
Problem
When you execute a query, you may get the correct number of rows, but some rows appear multiple times and others do not appear at all.
This behavior is typically because the primary key is configured incorrectly. If the database adapter reads two different rows that it thinks are the same (for example, the same primary key), then it writes both rows into the same instance and the first row's values are overwritten by the second row's values.
Solution
Open Application Sources > TopLink > TopLink Mappings. In the Structure window, double-click PHONES. On the first page, you should see Primary Keys. Make sure that the correct columns are selected to make a unique constraint.
Save and then edit the database partner link.
Click Next to the end, and then click Finish and Close.
Open your toplink_mappings.xml file. For the PHONES descriptor, you should see something like this:
<primary-key-fields>
<field>PHONES.ID1</field>
<field>PHONES.ID2</field>
</primary-key-fields>
Thanks
Steve -
Master-Detail only shows the first record of the Master's data
I have an ADF Master Table, Detail table. I use ExcuteWithParams on the Master Table. When executed from a button (Button has partial submit = true for button, Master Table has PartialTrigger on button, and Detail table has PartialTrigger on Master table and button), it works fine. However, I want to pass the parameters in pageFlowScope variables, and have the ExecuteWithParams invoked upon page load. When I try to do this, the Detail table only shows the first record of the Master's data, no mater what row is clicked on the Master table.
Master table now has no PartialTrigger, and Detail table has PartialTrigger on Master table. In my pageDef, I used an invoke action as follows:
<invokeAction Binds="ExecuteWithParams" id="invokeExecuteWithParams"
Refresh="always"/>
What am I missing? I am using verion 11.1.1.3. Any help would be much appreciated.
Thanks,
JessicaYes, it works when I drag the data control as a master detail without filtering any data. I want the user to be able to set search criteria to filter the data in the master table (For example, only pull back data with a transaction date between :startdate and :enddate). I can get it to work if I execute from an executewithparams button on the page, but not if I want to invoke the executewithparams upon page load with the parameter set by pageflowscope variables.
Thank you for responding.
Jessica -
Getting the next record in a jlabel??
Hi all,
I created a form to get some data from the database and when I press the down key it show get the next record in a jlabel.
I tryed to write this code but it gets only the first record and never get the second one always the first record.
private void getStd() {
rSetStd = dbConn.getRset(stdQry);
try {
if (rSetStd.next()) {
if (keyString.equals("Down")) {
lblStdId.setText(rSetStd.getString(1));
rSetStd.next();
} catch (SQLException e) {
private void txtStdName_keyPressed(KeyEvent e) {
int i = e.getID();
if (i == KeyEvent.KEY_TYPED) {
char c = e.getKeyChar();
keyString = "key character = '" + c + "'";
} else {
int keyCode = e.getKeyCode();
keyString = KeyEvent.getKeyText(keyCode);
getStd();Regards,Use [key bindings|http://java.sun.com/docs/books/tutorial/uiswing/misc/keybinding.html] instead.
See [this post|http://forums.sun.com/thread.jspa?messageID=10932017#10932017] for forum user Kleopatra's sound decision tree between the various approaches to implement key-based interactions. -
Security Agent: Could not get the user record from OpenDirectory
Hi,
Two months ago I had to change my SSD due to a damage at the old one. In the Apple shop they installed OS X Lion with a image from their image-server.
After that the Mac was quite slow in booting. With the old SSD (128 GB) booting takes 25 sec now it takes 75 sec.
I tried different things to solve the problem without result. First I asked in the shop, then I googled the problem all with no real solution.
Today now I searched in the log files. I found the following:
09.02.12 11:03:07.861 SecurityAgent: Could not get the user record from OpenDirectory.
09.02.12 11:03:07.861 SecurityAgent: Will sleep 3 seconds and try again (retryCount = 10)
09.02.12 11:03:34.907 SecurityAgent: Could not get the user record from OpenDirectory.
09.02.12 11:03:34.907 SecurityAgent: Will sleep 3 seconds and try again (retryCount = 1)
09.02.12 11:03:34.907 SecurityAgent: Will sleep 3 seconds and try again (retryCount = 1)
09.02.12 11:03:38.653 WindowServer: kCGErrorFailure: Set a breakpoint @ CGErrorBreakpoint() to catch errors as they are logged.
09.02.12 11:03:58.245 SecurityAgent: User info context values set for andi
09.02.12 11:03:58.246 SecurityAgent: User info context values set for andi
09.02.12 11:03:58.356 SecurityAgent: Login Window login proceeding
09.02.12 11:03:58.356 SecurityAgent: Login Window login proceeding
This operation takes 30 secs during the boot process. Can somebody help me, to solve this problem?
Regards
Andreas
MacBook Pro, Mid 2009
2.66 GHz Intel Core 2 Duo
8GB 1067 MHz DDR3
SAMSUNG SSD 830 Series , 256 GB
OS X 10.7.3cece2bali wrote: "it seems that your mac tries to connect to a server while booting. This action will erase all your network configuration..."
Where can I go to learn more about this 'erasure' of network configuration if the mac tries to connect to a server while booting?
I get the same error message as the OP. My account is an Admin on the machine. It's configured to automatically log in on boot -- except sometimes it fails. It has a login-item which runs a bash script that makes an https request to a nearby machine. Maybe I should make this script sleep a while so the https action happens after the boot sequence is done? (unlike SmashHuevo, my user needs to be an Admin) -
How to get the last record from the database
I am using MS Access database and Swings as GUI. I want to get the last record of a particular column from the table and store it as a varaible.
Hi
To get Last record of resultset, you have pass some parameter in constructor of CreateStatement.In such case Resultset should be scrollable and Readonly
Example
objStatement=objCon.createStatement ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
mwwResultSet=cwwStatement.executeQuery(mwwSqlQuery);
while(mwwResultSet.next())
if(mwwResultSet.isLast())
//Fetch the required column record.
String abc=mwwResultSet.getString(1);
I think this will work. Try it.
bye -
How to get the last record of an internall table ....
Hi All..
i want to get the last record of an internal table itab, and i want the the value of the last record.Hi,
Use describe statment.
data: lv_line type i.
Describe table itab lines lv_line.
read table itab into wa_itab index lv_line.
regards,
Santosh Thorat -
Anytime I print any Microsoft KB article, I only get the first page worth of text. This is very troubling because the articles are typically long, and I only get 1 page. The second page always comes out blank (even though in IE it will print out multiple pages with all the text).
My specific example today is listed in the URL below. This example will only print to the "DIR" command, I don't get the full page printed out.
Anyone else have this problem? Anyone have a resolution? I hate having to hit up IE just to print a single article.
I updated to FF 8.01 just to make sure, and I have tried different printers and even computers, to no avail. Even the print preview has the issue, only the first page worth of text is printed and the second page is always blank (even if there are 3, 4, 5, etc pages of data to be printed).
I have also tried the Firefox Menu -> Print command, and the "on-page" print command. I have seen moderate success with highlighting all the text that I want to print and going to "Print-Selection" but it is ugly.
Any feedback or assistance is greatly appreciated.'''Try the Firefox Safe Mode''' to see how it works there. The Safe Mode is a troubleshooting mode, which disables most add-ons.''
''(If you're not using it, switch to the Default theme.)''
* You can open the Firefox 4.0+ Safe Mode by holding the '''Shift''' key when you use the Firefox desktop or Start menu shortcut.
* Or use the Help menu item and click on the '''Restart with Add-ons Disabled...''' menu item while Firefox is running.
''Don't select anything right now, just use "'Start in Safe Mode"''
''To exit the Firefox Safe Mode, just close Firefox and wait a few seconds before using the Firefox shortcut (without the Shift key) to open it again.''
'''''If it is good in the Firefox Safe Mode''''', your problem is probably caused by an extension, and you need to figure out which one.
Please follow the [[Troubleshooting extensions and themes]] article for that.
''When you figure out what's causing your issues, please let us know. It might help other users who have the same problem.''
Maybe you are looking for
-
What's wrong with update 7.1.1?
I am tried to update my iphone 5 for 7.1.1 and now i have a brick. Iphone ask me to connect iTunes and standing in recovery mode. It's ********, I can't download new firmware that have size 1.2 GB. Thank you Apple and **** you!!!!
-
Update key in parent and child tables
Situation: Parent table (p) has a PK, p.parent_id. Child table (c) has a FK c.parent_id which, of course, points back to PK, p.parent_id. I need to UPDATE the key in both tables but I am concerned about throwing a FK constraint violation. How does on
-
Execution failed with error code 1
I am developing a simple Hello Server Application using the latest Netbeans 7.0 (Full Version that includes J2SE, J2ME,...etc). The code compiles fine and runs great on a Windows 7 SP1 (32-bit) just fine. but when trying to run it on a Windows 7 SP1
-
heya
-
WS_DELIVERY_UPDATE suppress information messages
I'm currently using WS_DELIVERY_UPDATE to pick and pgi my delivery. However, when doing so it pops up an information message of V1166 "Oldest of open items is overdue". This is a program that is going to be doing mass picking/pgi so it's not ideal