Reply to 2 foreign keys to the same table - multitable selection query problem

Your name:

Reply:


Posted by chrisek on 06/23/06 09:42

Hello,

I have 2 tables:
- Customers with columns:
customerID(prim_key),
customerName(with customer's names)
- Deliveries with columns:
deliveryID(primKey),
sender(ref_key to CustomerID from Customers),
receiver(also ref_key to CustomerID from Customers);

I need to select all data about deliveries, but instead of having
sender's ID and receiver's ID, I need to have their Names.

I tried to do:

SELECT
deliveries.deliveryID,
Customers.customerName AS sender,
Customers.customerName AS receiver
FROM
customers, deliveries
WHERE
Customers.customerID=Deliveries.sender AND
Customers.customerID=Deliveries.receiver;

But this only works if sender=receiver, which is obvious ;)
I'd like to know if there is any other way for obtaining those data
within one query

Thank you very much for your help
Chris

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация