Are you trying to get the secretary's name as the master table?
mlmcc
Main Topics
Browse All TopicsI have a SQL statment that runs against a MySQL 4.0 from a crystal report (XI). The report runs slowly and I think its because the SQL is too complicated. Can anyone help to simplify it. The table structure is below the query
SELECT User.FullName,User_1.FullN
FROM User AS User_1
INNER JOIN (
((User INNER JOIN Customer ON User.UserID = Customer.UserID)
INNER JOIN Secretary ON Customer.CustomerID = Secretary.CustomerID)
INNER JOIN Task ON Secretary.SecretaryID = Task.SecretaryID)
ON User_1.UserID = Secretary.UserID;
Table:USER1
UserID -PK
FullName
Table:USER
UserID -PK
FullName
Table:CUSTOMER
CustomerID -PK
UserID
Table:SECRETARY
SecretaryID -PK
UserID
CustomerID
Table:TASK
TaskID -PK
SecretaryID
TimePosted
TimeAccepted
TimeReturned
TimeCompleted
NumLines
Please help as the clients are baying for my blood.....
Seb
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
So the aim of the query is to get a report that details which tasks were done by which member of which customer (the customer is a company).
The user is related to user 1 as a many user1 to one user relationship
user-customer is a one to one relationship
customer to secretary is a many secretaries to one customer relationship.
Secretary to task is a many tasks to one secretaries relationship
Im not sure that I can get an EXPLAIN statement for the SQL
Does this help?
Seb
I think you have made your relationships a little too complicated. What is the difference between a company and a user? If they are a 1-1 relationship, what is the reasoning behind separating the data?
Each customer (a company, or YOUR customer) has a user account (1-1 relation). Each customer has a number of secretaries (1-many). Each secretary can have a number of tasks (1-many). So why are you relating secretary to the user? By your description, the user should be dependent only on the company, or vice versa.
Given what you've described, you have a task that was completed by a secretary. That secretary is a child of a customer, which should also yield the user. In the secretary table, you also relate it directly to the user...why? The query below reflects how I understand the relationships. Please explain further regarding the nature of the relationship between Customer and User.
SELECT * FROM Task a INNER JOIN Secretary b ON a.SecretaryID=b.SecretaryI
The user table contains the fullName of every user, whether they are a customer or a secretary. I want to group all the tasks done by each secretaries (listed by name- an attribute of the user table) under each customer (and list the customer name, which I can only get from the user table). How do I get the secretary fullName from the User table which I have already used?
Seb
I understand now. I disagree with using the user table to show customer name, since you equate a customer with a company, but the relationship makes more sense. Try this:
SELECT user_sec.FullName,user_cus
Task.TimeAccepted,Task.Tim
Secretary.SecretaryID
FROM Task INNER JOIN Secretary ON Task.SecretaryID=Secretary
INNER JOIN Customer ON Customer.CustomerID=Secret
INNER JOIN User user_sec ON Secretary.UserID=user_sec.
INNER JOIN User user_cust ON Customer.UserID=user_cust.
Business Accounts
Answer for Membership
by: routinetPosted on 2008-05-17 at 18:02:59ID: 21591243
Please explain a little about the nature of your table relationships and the goal of the query. Also, post the results of EXPLAIN for this query.