Solved

UNION Where not in MySQL

Posted on 2015-01-06
3
145 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

734 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