tags:

views:

38

answers:

3

Hi there , my situation is that i have one to many relation ,like order and orderdetails ,i need to get order which has single order details.

A: 

How about:

select * 
from order
where order_number in
    (select order_number
     from order_details
     group by order_number
     having count(*) = 1)
pm_2
thanks pm_2 this works great
Ahmed
A: 
Select o.*
from order o inner join order_detail d on o.id = d.order_id
group by o.*
having count(1) = 1
Scorpi0
Which SQL products does this work on? GROUP BY * is not Standard SQL. Doesn't work on SQL Server either.
onedaywhen
I don't know which are the column's table of the OP !! But he has to list them all in the group by.
Scorpi0
A: 
SELECT O1.order_number
  FROM Orders AS O1
 WHERE 1 = (
            SELECT COUNT(*)
              FROM OrderDetails AS D1
             WHERE O1.order_number = D1.order_number
           );
onedaywhen