customers table
| id | name | email |
| 1 | richa| richa@gmail.com |``
| 2 | sam | sam@gmail.com |
| 3 | hella| hella@gmail.com |
orders table
| id | customer_id |
| 101 | 1 |
| 102 | 2 |
| 103 | 3 |
order_product table
| id | order_id | product_id |
| | 101 | 1 |
| | 102 | 1 |
| | 103 | 2 |
products table
| id | product_name |
| 1 | Mobile |
| 2 | AC |
| 3 | Fridge |
These are tables, I want to display customers who buy only one type of products(can be multiple) but did not buy any other products.
$resultArr = $this->db->table('customers')``
->join('orders', 'orders.customer_id = customers.id')
->join('order_products', 'order_products.order_id = orders.id')
->select('customers.id, customers.name, customers.email');
->groupBy('customers.id');
->where('order_products.product_id', > 0);
return $resultArr;
I added this query but i did not get required data. can anyone give any idea or explain me if i did any mistake in it let me know. Thanks in advance.