View previous topic :: View next topic
|
Author |
Message |
dsivapradeep
New User
Joined: 06 Jul 2012 Posts: 43 Location: INDIA
|
|
|
|
Hi,
In unload datacard of BMC utility (PGM=ADUUMAIN), how to select only the first record out of multiple rows ?
For ex: primary key is (Branch + Account + Date). I want to retrive all the records of the table but only of latest date records for an unique (Branch + Account) combination. To get latest date i wrote ORDER BY branch asc, account asc, date desc.
But don't know how to select only the first record for a unique combination of Branch + Account.
Something like EQUALS option in DFSORT i was searching.
Any pointers on this would be helpful. |
|
Back to top |
|
|
harithb
New User
Joined: 08 Jun 2009 Posts: 15 Location: Bangalore
|
|
|
|
Hi,
Can you try combining your query with FETCH FIRST ROW ONLY and see if it works..
Cheers,
Haritha |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3076 Location: NYC,USA
|
|
|
|
Did you try with Group by and MAX combination? could you please provide sample data ? |
|
Back to top |
|
|
sushanth bobby
Senior Member
Joined: 29 Jul 2008 Posts: 1020 Location: India
|
|
|
|
Try something like this,
Code: |
select a.branch, a.account, a.date
from table a
where a.date = ( select max(date) from table
where account = a.account
and branch = a.branch)
order by a.branch, a.account
|
Regards,
Sushanth |
|
Back to top |
|
|
sandip_mainframe Warnings : 2 New User
Joined: 20 Sep 2006 Posts: 63 Location: pune
|
|
|
|
Hi,
You can use below query as FETCH FIRST ROWS clause works in BMC utility -
Code: |
SELECT BRANCH, ACCOUNT, DATE
FROM XYZ
ORDER BY DATE
FETCH FIRST 1 ROWS ONLY |
Thanks,
Sandip Walsinge |
|
Back to top |
|
|
sushanth bobby
Senior Member
Joined: 29 Jul 2008 Posts: 1020 Location: India
|
|
|
|
In BMC Unload if you give DIRECT NO, you can give all valid SELECT statements as they will be executed as dynamic queries. |
|
Back to top |
|
|
sureshpathi10
Active User
Joined: 03 May 2010 Posts: 158 Location: Kuala Lumpur
|
|
|
|
Sandip,
Your query will return only one record of any account number, which has smallest date.
But the requirement is to get all the account number's first records.
Sushanth query will work as expected.
dsivapradeep, have you tried ? |
|
Back to top |
|
|
dsivapradeep
New User
Joined: 06 Jul 2012 Posts: 43 Location: INDIA
|
|
|
|
Hey all,
Thanks for all your suggestions. I was not expecting any WHERE clauses in my UNLOAD DATACARD. We're supposed to reduce DBA effort, so simple SELECT operation i'll be using
It's easy to get answer for my question using a WHERE clause but I was searching for some specific CONTROL PARAMETERs by avoiding WHERE clause.
I'll use a DFSORT step and removes extra records that came out of this unload file.
Sandip, I think your query may not give my desired output. |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3076 Location: NYC,USA
|
|
|
|
If you could have mentioned this clearly in the question then someone could have given better solution and can save time as well.
however we are glad you found something useful. |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3076 Location: NYC,USA
|
|
|
|
DIRECT YES: UNLOAD PLUS reads data directly from the table space data set or image copy data sets to unload the data, using a SELECT-like syntaxfor data selection. SELECT functionality is a limited subset of thefunctionality that is normally available in DB2 SQL. The benefit of the DIRECT YES mode is maximum performance when unloading large volumes of data.
DIRECT NO: UNLOAD PLUS processes the SELECT statement and reads the data usingDB2 dynamic SQL. This mode is not a high-performance solution for unloading large volumes of data. The benefit of the DIRECT NO mode is a full range of DB2 SQL SELECTfunctionality, including joined tables, subqueries, and so on. This functionality includes many of the features that are availablein UNLOAD PLUS including DB2 parallelism, data type conversions, output formatting
This might be helpful to you. If you have proper indexing then with above options and suggested query this should not be a performance issue. Let us know the volume of the underlying data here or MIPS which might get used in this process. |
|
Back to top |
|
|
|