• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 313
  • Last Modified:

sql query question oracle

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
Brant Snow
Asked:
Brant Snow
2 Solutions
 
slightwv (䄆 Netminder) Commented:
select order_number from orders where sku like '40%'
minus
select order_number from orders where sku like '406%'
0
 
HainKurtSr. System AnalystCommented:
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

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now