DaveEverFade Posted October 4, 2007 Share Posted October 4, 2007 I have 2 tables as follows: Customer: cust_id cust_name Orders: order_id cust_id I need to have a distinct select of the these but to only bring back one result per customer. This is what I have SELECT DISTINCT * from Customer LEFT JOIN Orders on (Customer.custid = Orders.cust_id) The only problem is that I get more than one result for each customer if there is more than one entry for said customer in the Order table. The above is only a simplified example to try to explain my issue. Essentially I need the sql structure to remain as it is but need some kind of way of getting the LEFT JOIN to be distinct.... Any ideas? Dave Link to comment https://forums.phpfreaks.com/topic/71816-distinct-join/ Share on other sites More sharing options...
DaveEverFade Posted October 4, 2007 Author Share Posted October 4, 2007 Oh... And please don't suggest SELECT DISTINCT * from Orders... etc etc.... Link to comment https://forums.phpfreaks.com/topic/71816-distinct-join/#findComment-361710 Share on other sites More sharing options...
Barand Posted October 4, 2007 Share Posted October 4, 2007 Not tested, but SELECT c.customer_name, o.order_id FROM customer c LEFT JOIN orders o ON c.cust_id = o.cust_id GROUP BY c.customer_name Link to comment https://forums.phpfreaks.com/topic/71816-distinct-join/#findComment-361956 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.