?
Solved

sql query question oracle

Posted on 2011-03-11
2
Medium Priority
?
311 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
[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
2 Comments
 
LVL 77

Accepted Solution

by:
slightwv (䄆 Netminder) earned 1400 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 60

Assisted Solution

by:HainKurt
HainKurt earned 600 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

650 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