Solved

Oracle SQL - filter records not used

Posted on 2012-12-20
4
357 Views
Last Modified: 2012-12-21
Hello all

I have this SQL bellow that search for all TL_RATE used on LOAD and gives me a count on how many times they where used.

But i would like to do the opposite.

I would like to search all rates that was never used on a load. That, i really dont know what to start with.

Probably i just need to update the bellow SQL.

How can i do that?

Thanks again for your help.


Full SQL:
SELECT
    COUNT(DISTINCT BILL),
    LOAD.RATE_KEY,
    R.FROM_LOW_KEY_VALUE,
    R.FROM_HIGH_KEY_VALUE,
    R.FROM_COUNTRY,
    R.TO_LOW_KEY_VALUE,
    R.TO_HIGH_KEY_VALUE,
    R.TO_COUNTRY,
    LOAD.CARRIER_ID,
    TR.EFFECTIVE,
    TR.DATE_INVALID
FROM 
    LOAD, TL_RATE TR, LANE_RATE_NETWORK R
WHERE
    BEST_DEP > TO_DATE('20090830','YYYYMMDD')
    AND LOAD.RATE_KEY=TR.RATE_KEY
    AND TR.LANE_ID=R.ID
    GROUP BY LOAD.RATE_KEY,
    R.FROM_LOW_KEY_VALUE,
    R.FROM_HIGH_KEY_VALUE,
    R.FROM_COUNTRY,
    R.TO_LOW_KEY_VALUE,
    R.TO_HIGH_KEY_VALUE,
    R.TO_COUNTRY,
    LOAD.CARRIER_ID, 
    TR.EFFECTIVE,
    TR.DATE_INVALID
ORDER BY COUNT(DISTINCT BILL) DESC;

Open in new window

0
Comment
Question by:Wilder1626
  • 3
4 Comments
 
LVL 22

Accepted Solution

by:
Steve Wales earned 500 total points
ID: 38711243
Something like this should get you all the rates that aren't in load

select *
from tl_rate
where not (tl_rate.rate_key in (select load.rate_key from load))
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 38711642
Hi sjwales

I think i'm missing one join somewhere cause i dont have any error and i done have any records also.

I think i have to also use this: AND TR.LANE_ID=R.ID
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 38711662
I worked the code.

Let me test like this

SELECT   *
  FROM   TL_RATE
 WHERE   NOT (TL_RATE.RATE_KEY IN (SELECT   LOAD.RATE_KEY FROM LOAD)
              AND NOT (TL_RATE.LANE_ID IN
                             (SELECT   LANE_RATE_NETWORK.ID
                                FROM   LANE_RATE_NETWORK)))
         AND TL_RATE.DATE_INVALID >
               TO_DATE (TO_CHAR (SYSDATE, 'YYYYMMDD'), 'YYYYMMDD');

Open in new window

0
 
LVL 11

Author Closing Comment

by:Wilder1626
ID: 38713113
Many thanks for your help

all good now
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

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…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

705 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now