[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

complicated Select Statement Order-Order Details

Posted on 2007-04-04
7
Medium Priority
?
643 Views
Last Modified: 2013-12-19
What is the query to retrive? All orders that, do not display orders where all the order_Details contain a code = ERD.

Order Table
OrderID OrderName
01            OfficeOrderA
02            OfficeOrderB
03            OfficeOrderC

Order_Detail Table
OrDetailID OrderID ItemName Code1            
01               01         pencil      ERD
02               01         ballpen       ERD
03               01         stappler      CDG
04               02         chair      ERD
05               02         table      ERD


Do dot display orders where all the order_Details
contain a code = ERD.

Select * from Orders where (?)

Thanks,
BG
0
Comment
Question by:blueglacier
7 Comments
 
LVL 35

Expert Comment

by:Raynard7
ID: 18854137
select o.* from Orders o where o.OrderID not in (select orderID from Order_Detail od where od.Code1 = 'ERD')
0
 
LVL 1

Author Comment

by:blueglacier
ID: 18854479
Ray

I want to Discard those orders that have all their Order Detail rows as ERD.

On the example tables above, only Order 1 will be returned. Becuase Order 2 has all the Order Details with code = ERD.

your solution will elimitate order 1 and 2.

BG
0
 
LVL 35

Accepted Solution

by:
Raynard7 earned 300 total points
ID: 18854600
sorry - so you want ALL the order details as erd

select o.* from Orders o where o.OrderID not in
(
select
    x.orderID
from
(
select od1.orderID, count(*) cx, sum(case when od1.code1 = 'ERD' then 1 else 0 end)  sx from  Order_Detail od1 group by od1.orderID
) x
where x.cx = x.sx
)

may work
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 27

Assisted Solution

by:sujith80
sujith80 earned 300 total points
ID: 18855554
select a.*
from orders a, (select distinct orderId from order_details where code1 <> 'ERD') b
where a.orderId = b.orderId
0
 
LVL 3

Assisted Solution

by:kimarti3
kimarti3 earned 300 total points
ID: 18857675
select * from orders where order_id in (select order_id from order_details where code1 != 'ERD')
0
 
LVL 7

Assisted Solution

by:RainMan82
RainMan82 earned 300 total points
ID: 18857735
select *
  from order a,
       order_detail b
 where a.orderid = b.orderid
   and a.orderid not in (select distinct x.orderid from order_detail x where x.code1 = 'ERD')
0
 

Assisted Solution

by:desiboy1974
desiboy1974 earned 300 total points
ID: 18863480
select *
  from order a
  where not exists(select 1 from order_detail b
where b.order_id=a.order_id
and b.code='ERD')
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
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…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
Via a live example, show how to take different types of Oracle backups using RMAN.
Suggested Courses

830 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