Solved

Exclude Data in Oracle Select Statment

Posted on 2011-09-27
8
341 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
[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
  • 5
  • 2
8 Comments
 
LVL 74

Expert Comment

by:sdstuber
ID: 36710058
>>>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 74

Expert Comment

by:sdstuber
ID: 36710061
ah, nevermind I figured it out, you want to exlude ONLY the max that is F
0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 36710079
Is this technically a duplicate of your other question:
http://www.experts-exchange.com/Database/Oracle/Q_27343374.html
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 74

Accepted Solution

by:
sdstuber earned 500 total points
ID: 36710087
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
 

Author Comment

by:gilnari
ID: 36710288
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 74

Expert Comment

by:sdstuber
ID: 36710319
>>> 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
ID: 36710702
By the way you guys are great.  You real came through for me in a pinch,
0
 
LVL 74

Expert Comment

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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

717 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