473,403 Members | 2,183 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,403 software developers and data experts.

Query Across Multiple Tables

I've interacted with SQL DBs for years in project/product management roles, although admittedly still a newbie when it comes to actually building and manipulating things within SQL directly. I've inherited a project and have spent hours trying to figure something by browsing through user docs and other posts and trying things but am still stumped - hence me calling in the experts! :)

What I am trying to finish building seemed like it would be pretty easy - it's basically a compatibility matrix between products. The information types I am working with are:

> Software Product Class (example: Intuit)
> Software Product (Quickbooks 2008, Quickbooks 2004, etc.)
> 3rd Party Product Class (example: Microsoft)
> 3rd Party Product (example: Windows XP, Word 2007, etc.)
> Integration Type (example: Operating System, Import, Sync, etc.)
> Support Level (example: Supported, Not Supported, etc.)

A sample of the end result of the matrix I'm trying to build would be something like:

Software Product | Int. Type | 3rd Party Product | Support Level
--------------------------------------------------------------------------
Intuit Quickbooks 2008 | Operating System | MS Windows XP | Supported
Intuit Quickbooks 2008 | Import | MS Word 2007 | Supported
Intuit Quickbooks 2004 | Import | MS Word 2007 | Not Supported

So here is what has been built so far specifically as far as tables:

LNProdClass
LNProdClassID (PK, int)
LNProdClassName (varchar (60))

LNProd
LNProdID (PK, int)
LNProdVersion (varchar (60))
LNProdRelease (varchar (60))
LNProdClassID (FK, int) <-- relates to LNProdClass.LNProdClassID

TPProdClass
TPProdClassID (PK, int)
TPProdClassName (varchar (60))

TPProd
TPProdID (PK, int)
TPProdVersion (varchar (60))
TPProdRelease (varchar (60))
TPProdClassID (FK, int) <-- relates to TPProdClass.TPProdClassID

Type
TypeID (PK, int)
TypeName (varchar (60))

SupLevel
SupLevelID (PK, int)
SupLevelName (varchar (60))

CompMap
MapID (PK, int)
LNProdID (FK, int) <-- relates to LNProd.LNProdID
TypeID (FK, int) <-- relates to Type.TypeID
SupLevelID (FK, int) <-- relates to SupLevel.SupLevelID
TPProID (FK, int) <-- relates to TPProd.TPProdID

I obviously have no problem running a query on CompMap, although since it is all ID-based my results obviously come out something like:

Software Product | Int. Type | 3rd Party Product | Support Level
--------------------------------------------------------------------------
1 | 1 | 1 | 1
1 | 2 | 2 | 1
2 | 2 | 2 | 2

What method that should be used to draw the *names* that relate to the *IDs* from the child tables is where I'm lost. I also haven't ruled out the possibility that a different table construct might accomplish this either.

Any suggestions on what to try or what reference material to view to help me figure this out would be greatly appreciated. Thanks in advance!
Jul 24 '08 #1
5 1288
ck9663
2,878 Expert 2GB
Use JOIN. I'm not good at looking at table structure and constructing the query. I'd rather see some sample record of the source tables and your desired output, sorry.

-- CK
Jul 24 '08 #2
Thanks so much for the quick reply CK.

***************
Here are some SELECTS and sample data - the first is the table that is designed to build the final output/matrix
***************

select * from
CompMap
WHERE MapID = 1

MapID LNProdID TypeID SupLevelID TPProID
----------- ----------- ----------- ----------- -----------
1 5 2 1 4


***************
Then here are the pieces/parts that relate to the IDs of the above tabe/sample:
***************

select * from
LNProdClass
WHERE LNProdIDClass = 1

LNProdClassID LNProdClassName
------------- ----------------
1 MyProduct


select * from
LNProd
WHERE LNProdID = 5

LNProdID LNProdVersion LNProdRelease LNProdClassID
----------- ------------- ------------- -------------
5 9.0 SR-2 1


select * from
TPProdClass
WHERE TPProdClassID = 1

TPProdClassID TPProdClassName
------------- ----------------
1 Windows


select * from
TPProd
WHERE TPProdID = 4

TPProdID TPProdVersion TPProdRelease TPProdClassID
----------- ------------- ------------- -------------
4 Vista Enterprise NULL 1


select * from
SupLevel
WHERE SupLevelID = 1

SupLevelID SupLevelName
----------- -------------
1 Certified

select * from
Type
WHERE TypeID = 2

TypeID TypeName
----------- -----------------
2 Operating System


***************
What I'm trying to end up with is data that looks something like this:
***************

--whatever query--

MapID Product Type Support Level 3rd Party Product
----------- ------------------ ----------- ------------- -----------------
1 MyProduct 9.0 SR-2 Operating System Certified Windows Vista Enterprise
Jul 24 '08 #3
Delerna
1,134 Expert 1GB
I will start you off and let you complete it
Expand|Select|Wrap|Line Numbers
  1. select MapID,LNProdClassName as Product
  2. from CompMap 
  3. join LNProdClass on CompMap.MapID=LNProdClass.LNProdIDClass
  4.  
so just keep addig extra joins and selecting appropriate fields
Expand|Select|Wrap|Line Numbers
  1. select MapID,LNProdClassName as Product,otherfield,otherfield
  2. from CompMap 
  3. join LNProdClass on CompMap.MapID=LNProdClass.LNProdIDClass
  4. join nexttable on joinfield=joinfield
  5. join nexttable on joinfield=joinfield
  6.  
Jul 24 '08 #4
I can't thank you enough Delerna! I haven't quite figured out WHY this works - that is to say, the SELECT draws the LNProdClassName field and I thought the only way to do this would be to include the LNProdClass table in the FROM - for example:

select MapID, LNProdClassName as Product
from CompMap, LNProdClass
etc...

But I will give this a shot a post if I have any issues. Thanks again!


I will start you off and let you complete it
Expand|Select|Wrap|Line Numbers
  1. select MapID,LNProdClassName as Product
  2. from CompMap 
  3. join LNProdClass on CompMap.MapID=LNProdClass.LNProdIDClass
  4.  
so just keep addig extra joins and selecting appropriate fields
Expand|Select|Wrap|Line Numbers
  1. select MapID,LNProdClassName as Product,otherfield,otherfield
  2. from CompMap 
  3. join LNProdClass on CompMap.MapID=LNProdClass.LNProdIDClass
  4. join nexttable on joinfield=joinfield
  5. join nexttable on joinfield=joinfield
  6.  
Jul 25 '08 #5
p.s: works perfectly! Thanks again for your help on this.


I can't thank you enough Delerna! I haven't quite figured out WHY this works - that is to say, the SELECT draws the LNProdClassName field and I thought the only way to do this would be to include the LNProdClass table in the FROM - for example:

select MapID, LNProdClassName as Product
from CompMap, LNProdClass
etc...

But I will give this a shot a post if I have any issues. Thanks again!
Jul 25 '08 #6

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

Similar topics

4
by: Bob Hotschins | last post by:
I've joined several columns from several tables, and I would like to perform a relevance match against these multiple columns. It looks something like this: SELECT * FROM table1 LEFT JOIN...
8
by: Rigga | last post by:
Hi, I am new to mysql and need help on how to join tables. I have a database which contains 4 tables, the main table contains information by date order and the other 3 contain data also in date...
11
by: deko | last post by:
If I release a new version of my mbd (in mde format) and users want to upgrade - how do they migrate their data? For example, if the original was released as data1.mde and then I release...
1
by: fong.yang | last post by:
I've got a database with about 300,000 records. There are several different tables that are set up the same way with identical fields. I have the same queries individually set up for each table. ...
3
by: mkjets | last post by:
I have worked for hours on trying to find a solution and have not figured it out. I am working in Access 2003. I need to create a query that takes values from 1 table and displays them in...
1
by: NS3687 | last post by:
In my work, very often I come across the scenario that the service team keep their information per month in seperate tables. Some time, the same month in 2 tables, some time one table per month. As...
6
by: gerbski | last post by:
Hi all, I am relatively new to ADO, but up to now I got things working the way I wanted. But now I've run into somethng really annoying. I am working in MS Access. I am using an Access...
3
by: sar68 | last post by:
I'm using Access 2007 on windows vista. Intel T7400 with 2.16 GHz and 2 gigs of ram. 64 bit os. If I run a query that goes across multiple tables, I get sensible results. However, if I run a...
3
by: sar68 | last post by:
I'm having trouble figuring out how to run a query. I have a multitable database describing boating accidents. One table includes injured occupants, another table included deceased occupants. Other...
4
by: dponce | last post by:
Hello again, I have come across a brick wall in my database. I am looking for a Query to show me the combined information from multiple tables on one report. Each table has its own Query showing...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
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...

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.