$phql = "SELECT Orders.*, OrderItems.is_bespoke FROM Orders INNER JOIN OrderItems ON Orders.id = OrderItems.order_id WHERE Orders.status = 'order' AND OrderItems.is_bespoke = '1' ORDER BY Orders.id";
$orders = $this->manager->executeQuery($phql);
foreach ($orders as $key => $value) {
debug($value->orders->name, false);
}
I am going round in circles with this one. The above gives me the following result:
Lisa Pickard
Lisa Pickard
Michael Handford
Nazia Yousaf
Georgina Crawford
Joy Wymark
Stuart Rose
Stuart Rose
Julie Bennions
Mcdonald Mcdonald
Graham Kindley
Graham Kindley
Kelvin Davies
Sarah Norie
Emma Sharp
What I'm trying to acheive is to find all orders that have an order item that is marked as a bespoke item is_bespoke = 1
which the above orders are like that but I get them twice if it's more than one item and I would like to limit it to one if possible with some kind of DISTINCT version. Using SELECT DISTINCT Orders.id, Orders.name etc etc doesn't seem to work.