Solved

sql query question oracle

Posted on 2011-03-11
2
297 Views
Last Modified: 2012-05-11
K to start off, this is a proof of concept question, this is not the actual data that i am having a problem with.  

So what i am looking to do is to find the additional order_numbers between 2 queries.  For example, using the table in the image

select order_number from orders where sku like '406%' is going to return 6 records
these are the order_numbers
101, 102, 103, 105, 107, 108

so say there is another query
select order_number from orders where sku like '40%' is going to return 8 records
these are the order_numbers
101, 102, 103, 104, 105, 106, 107. 108

What i need to do is compare these two query results to find out the additional order_numbers in the second query that arent in the first so
104, 106

Obviously in this example it is simple to see the differences but like i said it is a proof of concept, i have already ran one query, it is being actively worked on so i just cant run the second query and get back all the results, i need to find the additions to be able to use.  

So to receive credit within one sql statement how can i compare the results of 2 select statements to find the additional order_numbers

I am on an oracle database but i would assume there is universal sql to handle this but perhaps not.
tempTable.jpg
0
Comment
Question by:Brant Snow
2 Comments
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 350 total points
ID: 35111579
select order_number from orders where sku like '40%'
minus
select order_number from orders where sku like '406%'
0
 
LVL 51

Assisted Solution

by:HainKurt
HainKurt earned 150 total points
ID: 35111819
or do this:

select t1.*
from
  (select *from orders where sku like '40%') t1
  left join
  (select order_number from orders where sku like '406%') t2
  on t1.order_number=t2.order_number
where t2.order_number is null
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Read about achieving the basic levels of HRIS security in the workplace.
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.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

860 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