473,836 Members | 2,091 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Combine these two Queries?

Is there any way to combine these two queries into one? I have tables
Item_Master & Kit_Master which are the source tables. Query 2 is using
both Item_Master (table) & qryKit1 (query) & Kit_Master (table) as its
record source because the Kit_Master table has 2 fields in it that get
joined back to the same field in Item_Master.

Item_Master key field is SKU
Kit_Master key fields are KitNo & ComponentNo

Item_Master - SKU contains a record for each Kit_Master - KitNo and
also for each Kit_Master - ComponentNo

qryKit1:
-----------
SELECT Item_Master.SKU , Item_Master.OnH and
FROM Item_Master

qryKit2:
-----------
SELECT Kit_Master.KitN o, Min(Item_Master .OnHand/[Qty]) AS Availability
FROM (Kit_Master INNER JOIN Item_Master ON Kit_Master.Comp onentNo =
Item_Master.SKU ) INNER JOIN qryKit1 ON Kit_Master.KitN o = qryKit1.SKU
GROUP BY Kit_Master.KitN o;

I can use two queries if I need to, I was just wondering if it could be
done. Thanks.

Aug 3 '06 #1
4 5749
I'm sure it is possible to combine your queries, but in order to make
the results come out as you desire you should post 3 samples of your
data -

1st - a few rows from the primary table

2nd - a few of the corresponding rows from the 2nd table

3rd - the rows from the desired resultset

So run your queries from your source tables and then show a few rows
from the resulting query. Then it will be easier to modify your queries
into 1 query.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Aug 3 '06 #2
Thanks for the response, here's the info you requested.

Item_Master (qryKit1 is the same)
---------------------------------------
SKU OnHand
55-1513-01 6600
69-0044-01 0
71-0831-01 51
84-0072-01 0
84-0113-01 59
501-00007-02 70
502-00008-01 438
55-0722-01 0
55-0840-01 65
55-0841-01 150
55-0941-01 224
55-1254-02 231
55-1255-01 199
55-1256-01 0
55-1257-02 80
55-1258-01 70
55-1259-01 32
55-1469-02 164
55-1513-01A 3550
55-1513-01B 452
55-1513-01C 2200
T NUTS 0
Kit_Master
---------------------------------------------------------------------
KitNo ComponentNo Qty
55-1513-01 55-1513-01A 1
55-1513-01 55-1513-01B 1
55-1513-01 55-1513-01C 1
69-0044-01 502-00008-01 1
69-0044-01 55-1254-02 1
69-0044-01 55-1256-01 1
69-0044-01 55-1258-01 1
69-0044-01 55-1259-01 1
71-0831-01 501-00007-02 1
71-0831-01 502-00001 1
71-0831-01 55-1469-02 1
84-0072-01 55-0722-01 1
84-0072-01 55-0840-01 2
84-0072-01 55-0841-01 4
84-0072-01 55-0941-01 1
84-0072-01 55-1254-01 1
84-0072-01 55-1255-01 1
84-0072-01 55-1256-01 1
84-0072-01 55-1257-02 1
84-0072-01 55-1258-01 1
84-0072-01 55-1259-01 1
84-0072-01 T NUTS 4
84-0113-01 55-0584-01 1
84-0113-01 55-1154-01 1
84-0113-01 55-1155-01 1
qryKit1:
---------------------------------------
SKU OnHand
55-1513-01 6600
69-0044-01 0
71-0831-01 51
84-0072-01 0
84-0113-01 59
qryKit2: (result I'm looking for - Availabilty)
---------------------------------------
KitNo Availability
55-1513-01 452
69-0044-01 0
71-0831-01 70
84-0072-01 0
84-0113-01 0
Rich P wrote:
I'm sure it is possible to combine your queries, but in order to make
the results come out as you desire you should post 3 samples of your
data -

1st - a few rows from the primary table

2nd - a few of the corresponding rows from the 2nd table

3rd - the rows from the desired resultset

So run your queries from your source tables and then show a few rows
from the resulting query. Then it will be easier to modify your queries
into 1 query.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Aug 3 '06 #3
Thanks. I was able to reproduce your queries with your data (thanks for
providing the original sql code, also) and I was able to get the same
query results as you using your query sql. Then I was able to modify
your query as follows.

This query should do the trick for you. Just paste the sql into a query
window.

SELECT t1.KitNo, Min(t2.OnHand/[Qty]) AS Availability
FROM (Kit_Master t1 INNER JOIN Item_Master t2 ON t1.ComponentNo =
t2.SKU) INNER JOIN (SELECT Item_Master.SKU , Item_Master.OnH and
FROM Item_Master) t3 ON t1.KitNo = t3.SKU
GROUP BY t1.KitNo;

BTW, if someone ever asks for data, it is always best to provide it in
DDL format

--------------------------------------
Create Table Item_Master(SKU Text(50), OnHand Integer)
Insert Into Item_Master
Select '55-1513-01', 6600 Union
Select '69-0044-01, 0 Union
...
----------------------------------------

I had to parse out all of your data by hand. The above code would be
run in VBA using DoCmd.RunSql. But hey, just glad to help.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Aug 3 '06 #4
Thanks, that's exactly what I was looking for!! And now that I see how
it's done, I'll be able to use it in future queries. Thanks again for
taking the time to help.

Rich P wrote:
Thanks. I was able to reproduce your queries with your data (thanks for
providing the original sql code, also) and I was able to get the same
query results as you using your query sql. Then I was able to modify
your query as follows.

This query should do the trick for you. Just paste the sql into a query
window.

SELECT t1.KitNo, Min(t2.OnHand/[Qty]) AS Availability
FROM (Kit_Master t1 INNER JOIN Item_Master t2 ON t1.ComponentNo =
t2.SKU) INNER JOIN (SELECT Item_Master.SKU , Item_Master.OnH and
FROM Item_Master) t3 ON t1.KitNo = t3.SKU
GROUP BY t1.KitNo;

BTW, if someone ever asks for data, it is always best to provide it in
DDL format

--------------------------------------
Create Table Item_Master(SKU Text(50), OnHand Integer)
Insert Into Item_Master
Select '55-1513-01', 6600 Union
Select '69-0044-01, 0 Union
..
----------------------------------------

I had to parse out all of your data by hand. The above code would be
run in VBA using DoCmd.RunSql. But hey, just glad to help.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Aug 3 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1771
by: Chris Lutka | last post by:
I've been racking my brains all day over this. And I'm not the best at SQL either. I need a query that will produce the following results: Product,Warehouse,Sold_LastYear,Sold_ThisYear,Sold_3Months,Sold_MTD I've got four queries to give me the Sold_* fields. Their fields are Product, Warehouse, and Units. I also have a table which these queries originated from. The table UV_SPPROD (I didn't name it) has Product, Warehouse, Period...
5
12997
by: Jamie Pittman via AccessMonster.com | last post by:
I have two tables with 5000 entries on them. One is based for regular time with several variables example (employee name, date,time in and out, code, customer, building) I have another table that works with overtime but has the same feilds within the table. I want to be able to run a report that combines the regular time and overtime for the warehouse and seperated by each customer. I have tried join tables but I keep ending with, (if it...
1
1454
by: Will | last post by:
Hi all I have a table, where there's AutoID, Name of Person (looked up from tblPerson), Name of Dispute (looked up from tblDispute), Date, Details (Memo). What I have is another table that need to look up to records in this table, but I couldn't because Access wouldn't let me look up just an AutoID on its own... So I created a new field in the table called Title. On the form it's basically =+; I can get it to work ok on the form but
4
4217
by: PlayHard | last post by:
I want my output in two columns like this: C_INCIDENT_TYPE \ TOTAL COUNT How do I combine my two queries to get result. First Query SELECT C_INCIDENT_TYPE, COUNT (*)
46
3103
by: dude88888 | last post by:
Hello I have one query where i get the total number of units for an entire fund say fund 89 has 1000 total units Then i need to find out how much of the total fund each user has say user 6 has 500 units say user 7 has 400 units
4
2083
by: | last post by:
I have query1 where I set a date range. Query2 is a crosstab query and is based on query1. I don't want the queries to be saved in the mdb but I do want them to be run in VBA using a querystring. If I only put query2 in the querystring it refers to query1 which is not available in the database. How can I combine the 2 queries into one querystring? Thank you, John
1
3169
by: csolomon | last post by:
Hello: I am using two queries to get one result set. The issue is, I return no data when I combine them into one query. I have listed both queries, as well as the 3rd query that shows them combined. **Max Date/Time Query-Finds the most recent updated record based on the time and date (Correct Results Returned) SELECT .panelNumber, Max(.locDate) AS MaxOflocDate, Max(.completionTime) AS MaxOfcompletionTime, .jobNumber, .panelID FROM , ...
2
1609
by: bips2005 | last post by:
i have got two queries, $sql1 = "select cust_id from customer where comp_name = '$compname'"; $result = $DB->query($sql1); $result->fetchInto($row); $sql = "select expirydate from customer l,domain s where l.cust_id = '$row' and s.domname = '$domname'"; the first query retrieves cust_id from the table customer and i use it in the second query to obtain expirydate.
13
3258
by: MNNovice | last post by:
I have three tables, tblAP, tblPayroll and tblAllocation. Each records three separate expenses. All three are related by FK ECHOID, each has common fields such as AccountNo, FundNo, GrantNo, SubClassNo, ProjectNo and Amount Originally I created these 3 and was able to generate combined reports using queries. But I have been unable to use these queries and tie it to create a report that will show Revenue, Expenses and balance side by side. ...
0
9670
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
10844
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
10548
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
10591
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
9374
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...
0
6979
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5649
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5826
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3115
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.