mysql - How to retrieve the rows in a table that has a value that appears NOT the most times? -


i have 2 tables.

a customers table , orders table.

customers:                          orders: customer_id      customer_name      orders_id   customer_id 1111             charles            1020        1111 2222             bertram            1021        1111 3333             barbare            1022        2222                                     1023        3333 

i want output be:

customer_name bertram barbara 

i want retrieve order bertram , barbara because have not placed order highest numbers of times.

the problem here subquery. know how count numbers of times customer has placed order, having real difficulties selecting customer_id occurs fewest times.

using mysql , apache

based on sample data, may finding customers 1 order, may use following query

select customer_name   customer c   join orders o     on c.customer_id = o.customer_id  group customer_name having count(orders_id) = 1 

result

customer_name bertram barbara 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -