When I try to get a random record into two tables from an Oracle database which have to a table is Order and order_detail. The result has to follow some condition that the order have 3 order_detail rows, and just retrieved a random order.
This is my code:
SELECT order_id
FROM Oder
INNER JOIN order_detail
ON orderId.order_id = order_detail.FK_order_id
WHERE order_id IN
(SELECT order_detail.FK_order_id
FROM order_detail
GROUP BY FK_order_id
HAVING COUNT(FK_order_id) > = 3
)
ORDER BY (SYS.DBMS_RANDOM.VALUE);
I DON'T KNOW WHERE TO PUT ROWNUM =1 TO GET ONLY ONE RECORD.