Sql-server – Trying to return empty rows even if data does not exsist in SQL

sql server

I am trying to return the last changed time for a list of users, but i would like to return a row even if the a last changed time does not exist

select  user_id, 
        last_changed_time = MAX(ISNULL(change_date_time,0))     
from audit_log_tx
where user_id in (users) 
group by user_id
order by user_id asc 

Best Answer

SELECT u.user_id, 
  column_name = COALESCE(MAX(change_date_time), '19000101')
  FROM dbo.users AS u
  LEFT OUTER JOIN dbo.audit_log_tx AS o
  ON u.user_id = o.user_id
  GROUP BY u.user_id;

Though I really don't like the use of token dates for missing data (especially 0).