By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,560 Members | 1,093 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,560 IT Pros & Developers. It's quick & easy.

query in conflict with a table

P: n/a
In my query, consisting of 2 tables, customers and orders,i get the
employeeid number ordered with a given customer.
The query is the following :

SELECT orders.orderid, Customers.Customerid, Customers.EmployeeID
FROM orders INNER JOIN Customers ON orders.customerid =
Customers.Customerid;

If i add on another table in the query, the tables Employees, then my
query
doesnt show anything.If i remove the table employes from the query,
then the query is
ok again.Obviously the table employees is not convenient for the
query. I need the table

Employees in order to from there the LastName of the
employee.The tables customers and employees are related one to many,
one employee may have many

customers.
How do you solve such problems with queries ?
Nov 12 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Perhaps:

SELECT o.orderid, c.Customerid, o.EmployeeID, e.LastName
FROM (orders as o INNER JOIN Customers as c
ON o.Customerid = c.Customerid) INNER JOIN Employees As e
ON o.EmployeeID = e.EmployeeID

Table design:

You should have the EmployeeID in the Orders table not in the
Customers table: an order has an employee (who handled the creation
of the order) and a customer (who requested the item). Customers
don't HAVE employees (unless you got something kinky going on). In
the Orders table the EmployeeID should be required, as should the
CustomerID - then you can't have an order w/o the person who requested
it & the person who handled it.
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQEJMC4echKqOuFEgEQLGJwCfW7J94dOI2G2o4ScG7atcIc bJoskAnRVM
GNqK13ghXBRhSd2F3NF+UEnb
=/H0r
-----END PGP SIGNATURE-----
Johm wrote:
In my query, consisting of 2 tables, customers and orders,i get the
employeeid number ordered with a given customer.
The query is the following :

SELECT orders.orderid, Customers.Customerid, Customers.EmployeeID
FROM orders INNER JOIN Customers ON orders.customerid =
Customers.Customerid;

If i add on another table in the query, the tables Employees, then my
query
doesnt show anything.If i remove the table employes from the query,
then the query is
ok again.Obviously the table employees is not convenient for the
query. I need the table

Employees in order to from there the LastName of the
employee.The tables customers and employees are related one to many,
one employee may have many

customers.
How do you solve such problems with queries ?


Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.