473,847 Members | 1,709 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Union Query with Union Criteria

36 New Member
Is it possible to create a union query that contains criteria from another union query?

I would like the query to only display the order numbers from TeamUnions that are either contained in FromMortASA and FromMortO.

Is that possible?

---
SELECT [order_num], [employee_id], [from_order_step _num], [to_order_step_n um], [move_time], [from_step_durat ion_sec]
FROM [dbo_FromMortO]
WHERE [order_num]=[TeamUnions].[order_number]
UNION
SELECT [order_num],[employee_id], [from_order_step _num], [to_order_step_n um], [move_time], [from_step_durat ion_sec]
FROM [dbo_FromMortAsA]
WHERE [order_num]=[TeamUnions].[order_number];
---
?? I'm sure that is wrong.
Oct 10 '07 #1
5 2599
FishVal
2,653 Recognized Expert Specialist
Hi, there.

Did you try this or read Access help topic "UNION operation"
By default, no duplicate records are returned when you use a UNION operation; however, you can include the ALL predicate to ensure that all records are returned.
Oct 10 '07 #2
ilikebirds
36 New Member
Hi, there.

Did you try this or read Access help topic "UNION operation"

Yes I have done both. What i'm trying to accomplish is to only Union the data from 2 tables that match the Order numbers from another Union Query.
Oct 11 '07 #3
FishVal
2,653 Recognized Expert Specialist
Hi, there.

Make joins and union them. Like this.

Expand|Select|Wrap|Line Numbers
  1. SELECT [dbo_FromMortO].[order_num], [dbo_FromMortO].[employee_id], [dbo_FromMortO].[from_order_step_num], [dbo_FromMortO].[to_order_step_num], [dbo_FromMortO].[move_time], [dbo_FromMortO].[from_step_duration_sec]
  2. FROM [dbo_FromMortO] INNER JOIN [TeamUnions] ON
  3. WHERE [dbo_FromMortO].[order_num]=[TeamUnions].[order_number]
  4. UNION
  5. SELECT [dbo_FromMortAsA].[order_num], [dbo_FromMortAsA].[employee_id], [dbo_FromMortAsA].[from_order_step_num], [dbo_FromMortAsA].[to_order_step_num], [dbo_FromMortAsA].[move_time], [dbo_FromMortAsA].[from_step_duration_sec]
  6. FROM [dbo_FromMortAsA] INNER JOIN [TeamUnions] ON
  7. WHERE [dbo_FromMortAsA].[order_num]=[TeamUnions].[order_number];
  8.  
Oct 11 '07 #4
ilikebirds
36 New Member
Hi, there.

Make joins and union them. Like this.
Thanksf or the tip. I ended up getting it to work:

SELECT dbo_FromMortO.o rder_num, dbo_FromMortO.e mployee_id, dbo_FromMortO.f rom_order_step_ num, dbo_FromMortO.t o_order_step_nu m, dbo_FromMortO.m ove_time, dbo_FromMortO.f rom_step_durati on_sec
FROM dbo_FromMortO INNER JOIN TeamUnions ON dbo_FromMortO.o rder_num=TeamUn ions.order_numb er
WHERE dbo_FromMortO.o rder_num=TeamUn ions.order_numb er;
UNION SELECT dbo_FromMortAsA .order_num, dbo_FromMortAsa .employee_id, dbo_FromMortAsa .from_order_ste p_num, dbo_FromMortAsa .to_order_step_ num, dbo_FromMortAsA .move_time, dbo_FromMortAsA .from_step_dura tion_sec
FROM dbo_FromMortAsA INNER JOIN TeamUnions ON dbo_FromMortAsA .order_num=Team Unions.order_nu mber
WHERE dbo_FromMortAsA .order_num=Team Unions.order_nu mber;
Oct 11 '07 #5
FishVal
2,653 Recognized Expert Specialist
You are welcome.

Best regards,
Fish
Oct 11 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
3962
by: s_gregory | last post by:
The mdb is considerable size 70 +- mb. A complex union query was working well, but when an additional union select... was added into the query, selecting identical fields from a different source, it began to have problems. Failure was observed only in a few PC's at first. For example, in an NT 4.0 SP6 PC, it continued to work OK. But in my Win 2k laptop, it failed. As the union query was gradually simiplified in testing, the failure...
14
1816
by: Salad | last post by:
A97. Situation: I have 3 tables with a text field in each and a date field in the first 2 tables: Table1 Text1, Date1 Table2 Text2, Date2 Table3 Text3 (no date field) The following makes up a saved query called Query1
5
1927
by: Alicia | last post by:
Hello everyone based on the data, I created a union query which produces this. SELECT ,,, 0 As ClosedCount FROM UNION SELECT ,, 0 AS OpenedCount, FROM ORDER BY , ;
3
3709
by: NoodNutt | last post by:
G'day ppl. Can anyone assist me with the correct structure of the following in a Union Query. tblBookings.FinYear tblBookings.DepPrefPay tblBookings.IntPrefPay tblBookingsFinPrefPay
7
3321
by: KoliPoki | last post by:
Hello every body. I have a small issue. Problem: I have a table with 4 descriptor columns (type). I need to formulate a query to retrieve a count for each type so I can group by...etc. The view I have works, but doesn't work when I supplement the query with some functions... they just don't like the UNION. The real problem is I can't change any of the udf's or queries, just the view. The view is inner joined back on to the primary...
2
1720
by: MLH | last post by:
I have a saved UNION query named qryAuthsOwnersAddnlOwnersLienholders4OneCar. Here it is... SELECT & " " & & " " & & " " & & ", " & & " " & & " " & "(" & & " county) " & Format$(,"(@@@) @@@-@@@@") & " " & IIf(=True,"(corporation)","(person)") AS Item, tblVehicleJobs.VehicleJobID, "X" AS OLAX, tblAddnlOwnrs.AddnlOwnrID AS
1
1617
by: ebasshead | last post by:
Hi Everyone I have four queries that Ive joined in a union query and want to add a date criteria ei between and including date A and date B. Ive tried a few things but getting errors. Can someone please guide me as to where it should go and how it should be written please. My code so far is below... SELECT , , , , , , , , FROM UNION SELECT , , , , , , , , FROM UNION SELECT , , , , , , , ,
2
2260
by: MLH | last post by:
Consider having tblCorrespondence, then copying & pasting it to tblCorrespondence1 - such that they are identical. Then consider the following UNION SELECT statement... SELECT tblCorrespondence.CorrespID, tblCorrespondence.VehicleJobID, tblCorrespondence.OutDate, tblCorrespondence.OutType, tblCorrespondence.OutProcessor, tblCorrespondence.InDate, tblCorrespondence.InRefDate, tblCorrespondence.InType, tblCorrespondence.InProcessor,...
6
7042
by: jmarcrum | last post by:
Hi! I have created a Union Query in ACCESS 2003, that combines 130 records from one query (Extra Foreman Radios) and 250 records from another query (Forman Main Radios). I have created a continuous form and used the Union query (qryRadioDataUnion) as my record source. My question is...how would i apply a filter to that query record source to allow the user to limit the search results down to an individual contractor, radio type, SIM card...
0
9886
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9730
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10983
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10647
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10706
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9482
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7882
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5911
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4119
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.