Solved

Exclude Data in Oracle Select Statment

Posted on 2011-09-27
8
335 Views
Last Modified: 2012-05-12
I need to run a select statement that exluces any records that have only 1 version and exclude any records Max(version) where Remvoved = 'F'

Data example is (name, version, removed) table is Analysis
XYZ, 1, F
ABC, 1, F
ABC, 2, F
ABC, 3, F
MNO, 1, F
MNO, 2, F

The value returned should be
ABC, 1, F
ABC, 2, F
MNO, 1, F
0
Comment
Question by:gilnari
  • 5
  • 2
8 Comments
 
LVL 73

Expert Comment

by:sdstuber
Comment Utility
>>>exclude any records Max(version) where Remvoved = 'F'

but all 3 of your expected values have removed = 'F'

why are they there if you're supposed to exclude them?
0
 
LVL 73

Expert Comment

by:sdstuber
Comment Utility
ah, nevermind I figured it out, you want to exlude ONLY the max that is F
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
Comment Utility
Is this technically a duplicate of your other question:
http://www.experts-exchange.com/Database/Oracle/Q_27343374.html
0
 
LVL 73

Accepted Solution

by:
sdstuber earned 500 total points
Comment Utility
S ELECT   name, version, removed
    FROM (SELECT a.*,
                 ROW_NUMBER() OVER (PARTITION BY name ORDER BY version DESC) rn,
                 COUNT(*) OVER (PARTITION BY name) cnt
            FROM analysis a)
   WHERE cnt > 1 AND NOT (rn = 1 AND removed = 'F')
ORDER BY name, version
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:gilnari
Comment Utility
Actaull the reference is one set of the issues this is other set where table was not update and the lesser version where never set as removed so I need to take the select statement and set removed to T.

so Sdstuber  how would I chnage this select statement to an update statement?
0
 
LVL 73

Expert Comment

by:sdstuber
Comment Utility
>>> how would I chnage this select statement to an update statement?

first you'll have to specify what do you want to update, and what you want the new values to be.

also,  that should be a new question, since it's a new requirement.

you can use the "ask a related question" link to tie them together if you want
0
 

Author Comment

by:gilnari
Comment Utility
By the way you guys are great.  You real came through for me in a pinch,
0
 
LVL 73

Expert Comment

by:sdstuber
Comment Utility
glad to help, and thank YOU for the kudos,  it's always nice to hear we're appreciated.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

743 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

12 Experts available now in Live!

Get 1:1 Help Now