Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesDatabase Management

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 29th, 2011, 07:16 AM
JvW JvW is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2011
Posts: 2 JvW User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 42 m 53 sec
Reputation Power: 0
Two table query within query

I have two tables (Access DB), one with product info, other with manuals info like this:

Table one:

Cat CDproduct Desc
1234 1001 Product 1001 belonging to Cat 1234
1234 1002 Product 1002 belonging to Cat 1234
5678 1010 Product 1010 belonging to Cat 5678
5678 9999 Product 9999 belonging to Cat 5678

Table two:

CDproduct Manual
1001 abcd1.pdf
1001 abcd2.pdf
1010 abcd3.pdf

Cat = Product Category, CDproduct = Product Code Indentifier

So in above table there is no manual for product 9999

I made a query to get a result matching "Cat", this works fine.
Now I want to use a single query on "CDproduct" comming from the original query "Cat"with a result that outputs Table one with a match on "Cat" and table 2 with a match on CDproduct, in other words, result should be products from table one, together with manuals from table two (if there is a manual found in table 2). Also products without manuals should be listed.

Any help in any direction is welcome.

Reply With Quote
  #2  
Old July 29th, 2011, 09:14 AM
MrFujin's Avatar
MrFujin MrFujin is offline
Lord of the Dance
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Oct 2003
Posts: 3,129 MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 22 h 57 m 20 sec
Reputation Power: 1736
Please post the code/query you have now.

You should take a look at the Left Join syntax.
This will "include all of the records from the first (left - product) of two tables, even if there are no matching values for records in the second (right - manual) table."

Reply With Quote
  #3  
Old July 29th, 2011, 02:39 PM
JvW JvW is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2011
Posts: 2 JvW User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 42 m 53 sec
Reputation Power: 0
Thanks for directing me the right way. Figured it out with LEFT JOIN like you mentioned.

For those who want to see how, here is the solution which worked OK for me:

Two tables: All_Products and Documentation
All_Products table contains main category named MainCategory
ProdCatID comes from user input, this case a web page.
Combined JOIN LEFT with WHERE statement to filter out user input.

"SELECT All_Products.MainCategory, All_Products.ProductID ,Documentation.ProductID " & _
"FROM All_Products " & _
"LEFT JOIN Documentation " & _
"ON All_Products.ProductID=Documentation.ProductID " & _
"WHERE All_Products.MainCategory ="&ProdCatID&"

Again thanks for your help MrFujin!

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > Two table query within query

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap