Solved

UNION Where not in MySQL

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

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to shrink a transaction log file down to a reasonable size.

759 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

16 Experts available now in Live!

Get 1:1 Help Now