USE hse;

CREATE OR REPLACE VIEW sat_form_logs_view AS
SELECT
  fl.user_id,
  COALESCE(u.employee_name, u.employee_id, CONCAT('user_id:', fl.user_id)) AS user_name,
  fl.title   AS form_name,
  fl.form_type,
  fl.description,
  fl.created_by,
  fl.location_name AS location,
  fl.created_at
FROM sat_form_logs fl
LEFT JOIN users u ON fl.user_id = u.user_id;
