473,473 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

(Newbie) Join problem.

Hi,
I'm new to SQL trying to use a base that was set up by another firm.
I can't get it to do what I want and I don't know if it's due to my
ignorance or bad table design ...

I have three tables
Sales
containing ProdID and Amounts

Products
containing ProdID and ProdTypeID and
ProdSubTypeID

Product-types
containing ProdTypeID and ProdTypeIDLabel and
ProdSubTypeID and ProdSubTypeIDLabel

I have to do some stats in Excel or in Crystal
totalling Amounts
grouped by ProductTypeLabel and
grouped by ProductSubTypeLabel.

Here's what I can do...
------------------------------
Using ProdTypeID, I can join Product-Types to Products,
and
using ProdID, I can join Products to Sales
and get a sum of amounts grouped by ProductTypeLabel. OK.

Also,
Using ProdTypeID, I can join Product-Types to Products,
and
using ProdID, I can join Products to Sales
and get a sum of amounts grouped by ProductSubTypeLabel. OK.
Here's what I can't do...
------------------------------
Get both (i.e. ProductTypeLabel and ProductSubTypeLabel) in the same report
and the correct amounts.

I have found a solution but it involves modifying the tables.
I create a new field with the Type and SubType concatenated in Products and
also in Product-Types (ProductTypeGlobal) and then join on that.
So,
Using ProductTypeGlobal, I can join Product-Types to Products,
and
using ProdID, I can join Products to Sales
and get a sum of amounts
grouped by ProductTypeLabel
AND
grouped by ProductSubTypeLabel
OK.

Is there some way to create the correct joins in SQL without creating the
new field?

Thanks

SQL Newbie.


Jun 1 '08 #1
0 1255

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

Similar topics

2
by: Bruce Duncan | last post by:
I'm a bit new to MySQL (know MS SQL well...and that may be the problem...getting the syntax confused) and I'm having a join problem...can anyone offer some help? Here's my problem: I have table1...
7
by: Greg | last post by:
I'm a quantitative securities analyst working with Compustat data (company fiscal reports and pricing feeds). My coworker came across a problem that we fixed, but I'd like to understand 'why' it...
12
by: Phil Powell | last post by:
<cfquery name="getAll" datasource="#request.dsn#"> SELECT U.userID, U.fname, U.lname, U.phone, U.lastLoggedIn, U.choiceId, U.experience, T.label AS teamLabel, R.label AS roleLabel FROM User U...
2
by: accessnovice | last post by:
Hello All! I am new to programming in the MS Access environment and decided to join this community due to various problems I encountered in Access 2000 and 2003. I began a small project in Access...
1
by: taoh15 | last post by:
Hi All Although I have been using SQL2K for a number of years this is my first venture into more complicated stuff. I have a query SELECT apd.elid , apd.pcid , apd.apstatid , ap.empid ...
3
by: Phillip B Oldham | last post by:
Hi. I'm stretching my boundaries in programming with a little python shell-script which is going to loop through a list of domain names, grab the whois record, parse it, and put the results into a...
17
by: takayuki | last post by:
Hi, I'm studying python via the exellent book "How to think like a python programmer" by Allen Downey. Noob question follows... animals.txt is a list of animals, each on a separate line:...
0
by: SQL-Newbie | last post by:
Hi, I'm new to SQL trying to use a base that was set up by another firm. I can't get it to do what I want and I don't know if it's due to my ignorance or bad table design ... I have three...
2
Lokean
by: Lokean | last post by:
Okay, this works, but there has GOT to be a cleaner way of doing this. Suggestions please. DECLARE @TMP TABLE ( HOLD1 NUMERIC, HOLD2 NUMERIC, HOLD3 NUMERIC, HOLD4 NUMERIC,
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
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...
1
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...
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,...
1
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...
0
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...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.