Joehamir Joehamir - 1 year ago 86
SQL Question

Mysql query get single order

hi guys please help me.

i want to get customer with single order.

i have customer table.

in my customer table i have

cu_id, cu_fname and cu_lname, cu_datecreated

and i have order table.

in my order tablei have

o_id, cu_id, cu_dateorder

here is the table



1 |joe |qwe |March-01-2016

2 |asd |gfh |March-03-2016

3 |zxc |vbn |March-05-2016



1 |1 |03-05-2016

2 |2 |03-10-2016

3 |2 |03-13-2016

4 |3 |03-20-2016

5 |1 |04-23-2016

I want to display the customer with single order.

Answer Source
select c.cu_id,c.cu_fname,c.cu_lname,c.cu_datacreated,o.o_id,o.cu_dateorder
from customer c
inner join order o on c.cu_id = o.cu_id
group by o.cu_id
having count(o.o_id)=1
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download