473,386 Members | 1,785 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,386 software developers and data experts.

help with main query using two inner joined subqueries

27
I have a main query that I would like to call two different subqueries.

In MS Access, I usually just save the two subqueries as separate queries which are then called by a third separate and main query. However, I'd like to put them all into one SQL command. Is this possible? Here are the queries:

-This query calls the other two queries below-
SELECT [Step 1].[Serial #], [Step 1].[Sub#], Format((([Step 2].Date)-([Step 1].Date)),"Fixed") AS [Time], [Step 1].Type
FROM [Step 1] INNER JOIN [Step 2] ON ([Step 1].[Serial #] = [Step 2].[Serial #]) AND ([Step 1].[Sub#] = [Step 2].[Sub#]);


Step 1
SELECT [Main Table].[Serial #], [Main Table].[Sub#], [Moving Info Table].Date, [Main Table].Type
FROM [Main Table] INNER JOIN [Moving Info Table] ON ([Main Table].[Sub#] = [Moving Info Table].[Sub#]) AND ([Main Table].[Serial #] = [Moving Info Table].[Serial #])
WHERE ((([Main Table].Type)="A" Or ([Main Table].Type)="O") AND (([Moving Info Table].[Status In])="Removal"));


Step 2
SELECT [Main Table].[Serial #], [Main Table].[Sub#], [Moving Info Table].Date, [Main Table].Type
FROM [Main Table] INNER JOIN [Moving Info Table] ON ([Main Table].[Sub#] = [Moving Info Table].[Sub#]) AND ([Main Table].[Serial #] = [Moving Info Table].[Serial #])
WHERE ((([Main Table].Type)="A" Or ([Main Table].Type)="O") AND (([Moving Info Table].[Status Out])="Quality"));


Any help or suggestions would be appreciated. Thank you!
Dec 6 '06 #1
2 2646
nico5038
3,080 Expert 2GB
I would start with skipping the space from the table and query name.
Personally I use a "qry" prefix for queries and "tbl" for tables to know where to find the origin.

In your case I would get:

qryMain:
select B.field1, B.field1
from qryStep1 A JOIN qryStep2 B (JOIN...)

When the above query works, you can simply replace the qryStep1 by the original query like:

qryMain:
select B.field1, B.field1
from (select field1 from tblStep1) A JOIN (select field1 from tblStep2) B (JOIN...)

Getting the idea ?

Nic;o)
Dec 6 '06 #2
NeoPa
32,556 Expert Mod 16PB
Sub-queries can be used within SQL using parentheses surrounding the sub-query.
Assigning a name to the sub-query is usual if referring to a field is required.
A simple display query which is equivalent to displaying a table 'tblThis' :
Expand|Select|Wrap|Line Numbers
  1. SELECT subQ.* FROM (SELECT * FROM tblThis) AS subQ
This is just some further clarification on the subquery part.
Dec 7 '06 #3

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

Similar topics

3
by: Prem | last post by:
Hi, I am having many problems with inner join. my first problem is : 1) I want to know the precedance while evaluating query with multiple joins. eg. select Employees.FirstName,...
10
by: Thomas R. Hummel | last post by:
I have a stored procedure that suddenly started performing horribly. The query plan didn't look right to me, so I copy/pasted the code and ran it (it's a single SELECT statement). That ran pretty...
5
by: Bob Stearns | last post by:
When I run the following query with the two sections commented out, the response time is between 1 an 2 seconds; with the first indicated section enabled, the response goes up to 15 seconds even...
12
by: Irene | last post by:
Hi all again, Well, I have my Athletics database with Athletes, Competitions, Scores tables. I have a ranking query where I get back the list of the competitions-athletes and scores...
9
by: MLH | last post by:
I have a table (tblCorrespondence) holding records with fields like , , , , , , , etc... About a dozen 's are defined and I often use queries to extract records of a given . That's pretty easy....
2
by: mmitchell_houston | last post by:
I'm working on a .NET project and I need a single query to return a result set from three related tables in Access 2003, and I'm having trouble getting the results I want. The details: ...
0
by: DukeSnyder | last post by:
I am trying to divide 2 subqueries. there is a comment in the query pointing out what I have unsuccessfuly tried. Can anyone lead me in the right direction please. SELECT TOP 100...
5
by: Bogdan | last post by:
Hi, I have a stored procedure that uses JOINs to return columns from multiple tables. I also have another stored proc that that takes a series of params and updates multiple tables. I used the...
8
by: Sham | last post by:
I am trying to perform the following query on a table that has been indexed using Full Text Search. The table contains multiple columns than have been indexed. (Below, all xml columns are...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...

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.