Thanks Björn and Aude.

FYI Björn, your method does not translate to MySQL
Aude's solution ("Company" AS Kind ) works fine though.

Thanks for the fast response, now I'm going to have to keep working ;-/

- Tom
On 15/02/2007, at 9:43 PM, Björn Eiríksson wrote:

In MS SQL Server I would do it like this: (Not promising that it works in other SQL databases)

(SELECT DISTINCT contacts.id, contacts.photo, Title, FirstName, LastName, Kind = 'Household' FROM Contacts JOIN Contacts_To_Households ON Contacts.id = Contacts_To_Households.ContactId
JOIN Households ON Contacts_To_Households.HouseholdId =  Households.Id
JOIN Customers ON Households.customerId = Customers.Id
WHERE Customers.id = '<customer.id>')
UNION
(SELECT DISTINCT contacts.id, contacts.photo, Title, FirstName, LastName, Kind = 'Company' FROM Contacts JOIN Contacts_To_Departments ON Contacts.id = Contacts_To_Departments.ContactId JOIN Departments ON Contacts_To_Departments.DepartmentId = Departments.id
JOIN Branches ON Departments.BranchID = Branches.id
JOIN Companies ON Branches.CompanyID = Companies.id
JOIN Customers ON Companies.customerId = Customers.Id
WHERE Customers.id = '<customer.id>')

Björn

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to