Reputation: 39
I need to get only the older order from transaction table for same customer
SELECT *
FROM Order_Cust
WHERE Status IN (15)
AND to_char(Order_date, 'yyyy') = 2020
I need order with order_date
to appear only.
Upvotes: 0
Views: 37
Reputation: 1
and u can try this!!
select * from Order_Cust
where order_date in (select max(order_date) from Order_Cust)
Upvotes: 0
Reputation: 521239
ROW_NUMBER
is one option here:
WITH cte AS (
SELECT t.*, ROW_NUMBER() OVER (PARTITION BY CustomerID ORDER BY Order_date) rn
FROM yourTable t
)
SELECT Order_Date, CustomerID, Order_Type
FROM cte
WHERE rn = 1;
Upvotes: 1