I have two tables called order and public holiday as following:
Order Table:
OrderId OrderDate
---------------------------
1 10 Mar 2017
Changed the table name of order to ordero as order is a Keyword
select ordero.orderid, ordero.orderdate, holiday.holidaydate,case when holiday.holidaydate is not null then 'Public Holiday'
else to_char(ordero.orderdate,'Day') end "Day"
from ordero left outer join holiday on ordero.orderdate=holiday.holidaydate;
Two things to remeber:
Possible solution:
SELECT O.OrderId,
O.OrderDate,
CASE
WHEN H.HolidayDate IS NOT NULL
THEN 'Public holiday'
ELSE TO_CHAR(O.OrderDate, 'Day')
END DAY
FROM ORDER_TABLE O
LEFT JOIN HOLIDAY_TABLE H
ON H.HolidayDate=O.OrderDate;
You can use an outer join like this:
SELECT OrderId,
OrderDate,
case when holidaydate is not null then 'Public holiday'
else to_char(OrderDate, 'Day') end as DAY
from orders
left outer join holidays
on OrderDate = holiday_date ;
If the dates match holidaydate
is not null so the CASE clause displays your desired string otherwise it displays the day of the orderdate
.
order
is a reserved word. Presumably your real table has a different name, to avoid the ora-00903
error. I have used orders
in my example, so you will need to edit my code to match your table name(s).