Solved

sql query question oracle

Posted on 2011-03-11
2
294 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

708 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now