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
2010-06-30 07:18:39
thanks pm_2 this works great
Ahmed
2010-06-30 09:11:43
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
2010-06-30 07:32:54
Which SQL products does this work on? GROUP BY * is not Standard SQL. Doesn't work on SQL Server either.
onedaywhen
2010-06-30 08:56:17
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
2010-06-30 09:08:59
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
2010-06-30 08:48:52