CREATE VIEW v_relays AS SELECT relays.*, controllers.uid AS controller_uid FROM relays INNER JOIN controllers ON controllers.id = relays.controller_id;