1

I have a two tables oc_order and oc_customer. I want to get customers who order more than once.

This is sample:

oc_order:

order_id | cus_id | cus_name
-------------------------------
1        | 1      | Kumar
2        | 2      | Vimal
3        | 1      | Kumar
4        | 3      | Ramesh

oc_customer

  cus_id   | cus_name |  cus_address
    -----------------------------------
    1        | Kumar    |  Chennai
    2        | Vimal    |  Coimbatore
    3        | Ramesh   |  Selam
    4        | Deepan   |  Chennai
    5        | Ashok    |  Coimbatore

For the above example i want to select only repeated order customer details only.

I mean now select only cus_id- 1 details, because customer one order more then one time.

This is the query am used

SELECT * 
FROM oc_order o 
LEFT JOIN oc_customer oc ON (o.customer_id = oc.customer_id) 
WHERE  (SELECT * 
        FROM oc_order 
        WHERE customer_id=o.customer_id)

1 Answer 1

1
SELECT c.*
FROM oc_customer c
JOIN oc_order o ON c.cus_id = o.cus_id 
GROUP BY c.cus_id
HAVING COUNT(o.order_id) > 1
2
  • Akina Thanks for your query please wait let me check
    – Ramesh S
    Commented Jul 16, 2018 at 6:48
  • Thanks for your code Its working. if you like this question please upvote this querstion
    – Ramesh S
    Commented Jul 16, 2018 at 6:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.