Solved

UNION Where not in MySQL

Posted on 2015-01-06
3
141 Views
Last Modified: 2015-01-06
I am trying to union 2 queries where 1 is not in the other for example
                 SELECT ToolType,PartNumber,Quantity,InsertDate,InventoryListID,LocationID FROM TEMP_PARTS Where InsertDate BETWEEN   
                '2012-01-01 12:00:00 AM' AND '2014-12-13 11:59:59 PM'
AND UNION ALL
//////////////WHERE partnumber not in the above query//////////////////////////
SELECT il.PartDesc as 'ToolType',il.PartNumber,ip.Quantity,CAST('2012-01-01 12:00:00 AM' AS DateTime) as 'InsertDate',il.UID as 'InventoryListID',ip.LocationID FROM
Inventory_Parts ip
JOIN Inventory_InventoryList as il ON il.UID = InventoryListID 
 WHERE ip.LocationID = 1 and il.isVisible = 1 

Open in new window

How do I do that?
0
Comment
Question by:r3nder
  • 2
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 40533885
you mean:
 SELECT ToolType,PartNumber,Quantity,InsertDate,InventoryListID,LocationID 
FROM TEMP_PARTS 
Where InsertDate BETWEEN   '2012-01-01 12:00:00 AM' AND '2014-12-13 11:59:59 PM'
UNION ALL
SELECT il.PartDesc as 'ToolType',il.PartNumber,ip.Quantity,CAST('2012-01-01 12:00:00 AM' AS DateTime) as 'InsertDate',il.UID as 'InventoryListID',ip.LocationID 
FROM Inventory_Parts ip
JOIN Inventory_InventoryList as il 
ON il.UID = InventoryListID 
 WHERE ip.LocationID = 1 and il.isVisible = 1 
 AND NOT EXISTS( SELECT null
FROM TEMP_PARTS tp
Where tp.InsertDate BETWEEN   '2012-01-01 12:00:00 AM' AND '2014-12-13 11:59:59 PM'
  AND tp.partnumber  = il.partnumber  ) 

Open in new window

0
 
LVL 6

Author Comment

by:r3nder
ID: 40533925
Hell yeah! that is what I mean thank you Sir
0
 
LVL 6

Author Closing Comment

by:r3nder
ID: 40533927
Thank you Guy
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

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. …
Creating and Managing Databases with phpMyAdmin in cPanel.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

837 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