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

Selecting the last date from mutiple duplicate records

4
I have a table in oracle that contains transaction data by item part number.
This means for each part number there will be more than one transaction date, what i am trying to extract is the last transaction date for each part number in a driving table.

so..
I have created a table that has 1 column named PART_NO, with numerous part numbers contained in it, i want to left join this to my transaction table and return the last transaction for those part numbers. The SQL so far is as follows:

Expand|Select|Wrap|Line Numbers
  1.  SELECT                  A.PART_NO,
  2.          OUTLET_NUM,
  3.         TXN_DATE
  4.  FROM   TRANSACTIONS  A,
  5.  
  6.  (SELECT MAX(TXN_DATE) AS MAXDATE, PART_NO
  7.  FROM TRANSACTIONS
  8.  GROUP BY PART_NO) MAXRESULTS 
  9.  WHERE A.PART_NO = MAXRESULTS.PART_NO
  10.  AND A.TXN_DATE = MAXRESULTS.MAXDATE
  11.  
This will return the last transaction for each part number in the transaction table, but i need to limit this to those records in my driving table as the statement takes an age to run. any ideas? Thanks in advance
Sep 5 '07 #1
2 6721
debasisdas
8,127 Expert 4TB
Try to create indexes opn the joined fields.

For more details please post all your involved tables structures.
Sep 5 '07 #2
amitpatel66
2,367 Expert 2GB
I have a table in oracle that contains transaction data by item part number.
This means for each part number there will be more than one transaction date, what i am trying to extract is the last transaction date for each part number in a driving table.

so..
I have created a table that has 1 column named PART_NO, with numerous part numbers contained in it, i want to left join this to my transaction table and return the last transaction for those part numbers. The SQL so far is as follows:

Expand|Select|Wrap|Line Numbers
  1.  SELECT                  A.PART_NO,
  2.          OUTLET_NUM,
  3.         TXN_DATE
  4.  FROM   TRANSACTIONS  A,
  5.  
  6.  (SELECT MAX(TXN_DATE) AS MAXDATE, PART_NO
  7.  FROM TRANSACTIONS
  8.  GROUP BY PART_NO) MAXRESULTS 
  9.  WHERE A.PART_NO = MAXRESULTS.PART_NO
  10.  AND A.TXN_DATE = MAXRESULTS.MAXDATE
  11.  
This will return the last transaction for each part number in the transaction table, but i need to limit this to those records in my driving table as the statement takes an age to run. any ideas? Thanks in advance
From the above Query, I see u have used the same table even in INLINE View. So I have re-structured the Query as shown below:

SELECT t.part_no,t.outlet_num, t.txn_date FROM TRANSACTIONS t WHERE
t.txn_date = (SELECT max(txn_date) from transactions where txn_date = t.txn_date and part_no = t.part_no group by part_no )

Try executing the above Query. Please do post back.
Sep 5 '07 #3

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

Similar topics

2
by: Riegn Man | last post by:
I have a problem with access and our time clocks. We have time clocks that put out a .log file with the badge swipes for everybody. There is one .log file for each day. I am pulling that data...
3
by: MostlyH2O | last post by:
Hi Folks, I have a query that joins 3 tables. One of the tables (SalaryData) has data where there may be duplicate records with different dates. Of those duplicate records, I want the query to...
3
by: MostlyH2O | last post by:
Hi Folks, I have a query that joins 3 tables. One of the tables (SalaryData) has data where there may be duplicate records with different dates. Of those duplicate records, I want the query to...
1
by: Ramesh | last post by:
hi, I am selecting fields from three table for manupulating data and i want to display total number of records selected. But i am always getting -1 value, eventhough 1000 of records are selected....
6
by: aaj | last post by:
Hi all I use a data adapter to read numerous tables in to a dataset. The dataset holds tables which in turn holds full details of the records i.e. keys, extra colums etc.. In some cases I...
48
by: phillip.s.powell | last post by:
MySQL 3.23.58 - 4.0.17 (yep, several database server instances, don't ask) I have database Spring with table Students I have database Summer with table Students I am tasked to produce a...
4
by: wishwish20 | last post by:
Hello, I am having trouble with an SQL query which is used as a source on a report. The database is being used to keep track of billing information. I have made an sql query, which has 2 tables....
5
by: mikevde | last post by:
Hi, Can anyone confirm whether it is possible to: a) use subqueries in mySQL b) use DISTINCT TOP in mySQL? I am trying to find a way to return the top 5 results in my table. For simplicity...
4
by: mcca0081 | last post by:
hi - i'm trying to delete one of the duplicate records based on the most current date. here's the code for my access 2000 db. any help would be appreciated!!! - thank you kindly Sub...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.