Hello Everyone
Long time user, first poster. Codeigniter is has really changed the way I code (for the better), but I’m struggling with an SQL concept that is sometimes needed.
I’m using the active record class and I need to join on the same table twice.
To explain I have an Orders table for an online shop which stores the ID’s for a billing address and delivery address, both which relate to the same table CustomerAddresses.
This would usually be achieved in normal MySQL syntax something similar to the following:
SELECT Orders.*, Billing.*, Delivery.* FROM Orders
LEFT JOIN CustomerAddresses AS Billing
ON Orders.BillingAddrID = Billing.ID
LEFT JOIN CustomerAddresses AS Delivery
ON Orders.DeliveryAddrID = Delivery.ID
WHERE Orders.ID = x
What is the best way to tackle this problem with the active record class?, or is it even possible as there seems no way to alias joined tables.
Thanks for any help in advance. ![]()
