Solved

sql query question oracle

Posted on 2011-03-11
2
300 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 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:Huseyin KAHRAMAN
Huseyin KAHRAMAN 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

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 describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
A company’s centralized system that manages user data, security, and distributed resources is often a focus of criminal attention. Active Directory (AD) is no exception. In truth, it’s even more likely to be targeted due to the number of companies …
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

733 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