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

reusing lookup table in DB design

13
I think I'm violating some database building principle here, but I don't know what it is, or how to work around it.

I have three tables (the example is a scaled-down version but structurally accurate):

theader -- header info about a customer
tdetail -- details about specific interactions with the customer
tanalyst -- a table storing employee names

The problem seems to be that I'm using tAnalyst as a lookup value in both tHeader and tDetail (an analyst might 'own' a customer, i.e., be stored in the header, and a totally different analyst might have some specific interaction with the customer and be stored in the detail table).

So there's a relationship between theader and tanalyst and a second relationship between tdetail and tanalyst.

This query acts appropriately, returning all the records in the detail table:
Expand|Select|Wrap|Line Numbers
  1. SELECT tHeader.MA, tDetail.CurrentAnalyst
  2. FROM tHeader INNER JOIN tDetail ON tHeader.MA = tDetail.MA;
This query returns only the detail record for the analyst on the header record:
Expand|Select|Wrap|Line Numbers
  1.  SELECT tHeader.MA, tDetail.CurrentAnalyst, tAnalysts.AnalystName
  2. FROM tAnalysts INNER JOIN (tHeader INNER JOIN tDetail ON tHeader.MA = tDetail.MA) ON (tAnalysts.AnalystID = tDetail.CurrentAnalyst) AND (tAnalysts.AnalystID = tHeader.PrimaryAnalyst);
Would greatly appreciate any insights. Thanks.
Jul 19 '07 #1
4 1598
hyperpau
184 Expert 100+
I think I'm violating some database building principle here, but I don't know what it is, or how to work around it.

I have three tables (the example is a scaled-down version but structurally accurate):

theader -- header info about a customer
tdetail -- details about specific interactions with the customer
tanalyst -- a table storing employee names

The problem seems to be that I'm using tAnalyst as a lookup value in both tHeader and tDetail (an analyst might 'own' a customer, i.e., be stored in the header, and a totally different analyst might have some specific interaction with the customer and be stored in the detail table).

So there's a relationship between theader and tanalyst and a second relationship between tdetail and tanalyst.

This query acts appropriately, returning all the records in the detail table:
Expand|Select|Wrap|Line Numbers
  1. SELECT tHeader.MA, tDetail.CurrentAnalyst
  2. FROM tHeader INNER JOIN tDetail ON tHeader.MA = tDetail.MA;
This query returns only the detail record for the analyst on the header record:
Expand|Select|Wrap|Line Numbers
  1.  SELECT tHeader.MA, tDetail.CurrentAnalyst, tAnalysts.AnalystName
  2. FROM tAnalysts INNER JOIN (tHeader INNER JOIN tDetail ON tHeader.MA = tDetail.MA) ON (tAnalysts.AnalystID = tDetail.CurrentAnalyst) AND (tAnalysts.AnalystID = tHeader.PrimaryAnalyst);
Would greatly appreciate any insights. Thanks.
You must have two separate fields for the analyst who owns the customer, and another field for the other analysts who might have had interactions with the customer. Then you can have them both lookup to the same table where the names of the analysts are stored.
Jul 19 '07 #2
RoseM
13
You must have two separate fields for the analyst who owns the customer, and another field for the other analysts who might have had interactions with the customer. Then you can have them both lookup to the same table where the names of the analysts are stored.
Sorry, maybe I'm not understanding -- I have two separate fields, one, theader.primaryanalyst, and two, tdetail.currentanalyst. They both look up values in tanalyst....
Jul 19 '07 #3
RoseM
13
Also, this query is a better example of what I'm talking about then the first query I posted. Again, this does work -- it returns everything, with fields for both primary and current analyst. It seems like it's only when I link to the analyst table (to get the full name, instead of just the ID) that it fails (or, more precisely, I fail);

Expand|Select|Wrap|Line Numbers
  1.  SELECT tHeader.PrimaryAnalyst, tDetail.CurrentAnalyst, tDetail.MA, tDetail.StartDate
  2. FROM tHeader INNER JOIN tDetail ON tHeader.MA = tDetail.MA;
Jul 19 '07 #4
RoseM
13
I think I got this -- it required two queries (or possibly some intricate joining from someone more highly skilled than myself). First, a query to join the header and details together, than a query against that returned recordset to pull in the analyst names.

If anyone thinks that this reuse of a lookup table violates some data integrity rule please post. It feels kind of wrong to me, but I can't quite get at why. When I look at the relationships in the visual interface the two lines snaking into this table is a little disturbing--it doesn't have the tidy structure I hope to see when I open that window.

Thanks.
Jul 19 '07 #5

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

Similar topics

9
by: Koen | last post by:
Hi all, My application uses a lot of lookup tables. I've splitted the frontend (forms, reports, etc) from the backend (data). The database has around 10 different users. The values in the...
7
by: Marco Simone | last post by:
Hi, What is your opinion about using Lookup field in table. I would like to use lookup field in table 1, so that I can choose data in combo box from table 2. Is this good design of database? ...
3
by: my-wings | last post by:
I've been reading about how evil Lookup fields in tables are, but I've got to be missing something really basic. I know this subject has been covered before, because I've just spent an hour or two...
1
by: Zachary Turner | last post by:
I want to make a Lookup Field based on another Lookup field. In other words, I have this table A with two fields: ID and Name, where ID is an Autonumber and Name is a friendly name. Then I have a...
3
by: google | last post by:
I have a database with four table. In one of the tables, I use about five lookup fields to get populate their dropdown list. I have read that lookup fields are really bad and may cause problems...
5
by: Kevin | last post by:
I was reading on the mvps.org site not to use the lookup wizard in the table design, but rather use a query. I'm confused by this, given that the lookup wizard basically creates a query and uses...
1
by: Nate | last post by:
Modeling of Lookup Values and ORM I know this is not the correct forum for object design patterns, but I haven't found any design related newsgroups. Scenario: Customers (table)...
11
by: Paul H | last post by:
Suppose I have a table called tblPeople and I want a field to illustrate whether each person prefers cats or dogs. I could do it one of three ways. 1. A plain text field Create a text field in...
1
by: paulquinlan100 | last post by:
Hi Im having problems getting a column in one of my tables to display the lookup values correctly. The database is split, in the backend the rowsource for this particular field is set to a...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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
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,...
0
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...

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.