473,320 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Union Query with Union Criteria

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_num], [move_time], [from_step_duration_sec]
FROM [dbo_FromMortO]
WHERE [order_num]=[TeamUnions].[order_number]
UNION
SELECT [order_num],[employee_id], [from_order_step_num], [to_order_step_num], [move_time], [from_step_duration_sec]
FROM [dbo_FromMortAsA]
WHERE [order_num]=[TeamUnions].[order_number];
---
?? I'm sure that is wrong.
Oct 10 '07 #1
5 2569
FishVal
2,653 Expert 2GB
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
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 Expert 2GB
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
Hi, there.

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

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
FROM dbo_FromMortO INNER JOIN TeamUnions ON dbo_FromMortO.order_num=TeamUnions.order_number
WHERE dbo_FromMortO.order_num=TeamUnions.order_number;
UNION 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
FROM dbo_FromMortAsA INNER JOIN TeamUnions ON dbo_FromMortAsA.order_num=TeamUnions.order_number
WHERE dbo_FromMortAsA.order_num=TeamUnions.order_number;
Oct 11 '07 #5
FishVal
2,653 Expert 2GB
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
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,...
14
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...
5
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
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
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...
2
by: MLH | last post by:
I have a saved UNION query named qryAuthsOwnersAddnlOwnersLienholders4OneCar. Here it is... SELECT & " " & & " " & & " " & & ", " & & " " & & " " & "(" & & " county) " &...
1
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...
2
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...
6
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.