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

x
?
Solved

complicated Select Statement Order-Order Details

Posted on 2007-04-04
7
Medium Priority
?
640 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
[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
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
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.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

618 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