Solved

UNION Where not in MySQL

Posted on 2015-01-06
3
142 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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

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. …
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

749 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