Replace return nulls in LEFT OUTER JOIN

SELECT        WO_BreakerRail.ID, indRailType.RailType, indRailType.RailCode, WO_BreakerRail.CreatedPieces, WO_BreakerRail.OutsideSource, WO_BreakerRail.Charged, WO_BreakerRail.Rejected, WO_BreakerRail.RejectedToCrop, WO_BreakerRail.Date
FROM            indRailType LEFT OUTER JOIN
                         WO_BreakerRail ON indRailType.RailCode = WO_BreakerRail.RailCode AND WO_BreakerRail.Date = @date

When this returns, the Date column has NULL values ​​that do not have matching rows from WO_BreakerRail. Is there a way to replace only these NULL values ​​with @date?

+5
source share
4 answers

In oracle and sql server you can use COALESCE ( oracle version )

SELECT ...., COALESCE(WO_BreakerRail.Date, @date)
+3
source

You can use the function COALESCE(go here for mysql documentation)

COALESCE(WO_BreakerRail.Date, @date)

or you can use a simple IF:

IF(WO_BreakerRail.Date IS NULL, @date, WO_BreakerRail.Date)
+2
source

, COALESCE, . COALESCE(WO_BreakerRail.Date, @date)

0

, MySQL IFNULL().

select
  ifnull(wo_breakerrail.date, @date) as `date`,
0
source

All Articles