Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Oracle - filter sequal issue

Posted on 2012-12-20
4
Medium Priority
?
426 Views
Last Modified: 2012-12-20
Hello all

I have a problem with a SQL.

I have this SQL bellow that i use to pull resources from a table.

The thing is that in TL_RESOURCE_TRLR A i may have multiple A.TRLR_TYPE_ID based on A.EFFECTIVE

So i only want to extract the most updated effective date per TRLR_TYPE_ID and not all the effective dates even the old one. Just the very last one

How can i update this?

Thanks again for your help


  SELECT   DISTINCT A.CARRIER_ID,
                    A.EFFECTIVE,
                    A.TRLR_TYPE_ID,
                    A.CURRENT_NUM_VEHICLES
    FROM   TL_RESOURCE_TRLR A, CARRIER_EQUIP B
   WHERE       A.CARRIER_ID = B.CARRIER_ID(+)
           AND A.TRLR_TYPE_ID = B.TRLR_TYPE_ID(+)
           AND B.CARRIER_ID IS NULL -- EXCLUDE ROWS ADDED BECAUSE  OF THE OUTER JOIN
ORDER BY   A.CARRIER_ID ASC;

Open in new window

0
Comment
Question by:Wilder1626
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 77

Accepted Solution

by:
slightwv (䄆 Netminder) earned 2000 total points
ID: 38710343
Try this:

select carrier_id, effective, trlr_type_id, current_num_vehicles
from
(
SELECT   A.CARRIER_ID,
                    A.EFFECTIVE,
                    A.TRLR_TYPE_ID,
                    A.CURRENT_NUM_VEHICLES,
row_number() over(partition by carrier_id order by carrier_id, effective desc) myrn
    FROM   TL_RESOURCE_TRLR A, CARRIER_EQUIP B
   WHERE       A.CARRIER_ID = B.CARRIER_ID(+)
           AND A.TRLR_TYPE_ID = B.TRLR_TYPE_ID(+)
           AND B.CARRIER_ID IS NULL -- EXCLUDE ROWS ADDED BECAUSE  OF THE OUTER JOIN
)
where myrn=1;


or a simple max?

SELECT   DISTINCT A.CARRIER_ID,
                    MAX(A.EFFECTIVE),
                    A.TRLR_TYPE_ID,
                    A.CURRENT_NUM_VEHICLES
    FROM   TL_RESOURCE_TRLR A, CARRIER_EQUIP B
   WHERE       A.CARRIER_ID = B.CARRIER_ID(+)
           AND A.TRLR_TYPE_ID = B.TRLR_TYPE_ID(+)
           AND B.CARRIER_ID IS NULL -- EXCLUDE ROWS ADDED BECAUSE  OF THE OUTER JOIN
group by carrier_id, trlr_type_id, current_num_vehicles
ORDER BY   A.CARRIER_ID ASC;
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 38710428
Hi slightwv

Let me look at this, i'm not having the same result in both SQL
0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 38710457
I might have fat-fingered when I retyped your SQL.

If you can provide some sample data and expected results, I can create an actual working example.
0
 
LVL 11

Author Closing Comment

by:Wilder1626
ID: 38711087
Hi again,

do you know what, i like the second one.

smaller but exactly what i need.

Thanks again for your help
0

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question