 USE `ica`;
 CREATE  OR REPLACE VIEW `conversations_themes_state_latest` AS
 SELECT
-	tbl_state.deleg_id AS deleg_id,
-	MAX(tbl_state.id) AS state_id
+  tbl_state.deleg_id AS deleg_id,
+  MAX(tbl_state.id) AS state_id
 FROM `conversations_themes_states` AS tbl_state
 GROUP BY deleg_id;
 

USE `ica`;
CREATE  OR REPLACE VIEW `contents_langs_state_latest` AS
SELECT
	tbl_state.lang_id AS lang_id,
	MAX(tbl_state.id) AS state_id
FROM `contents_langs_states` AS tbl_state
GROUP BY lang_id;


USE `ica`;
CREATE  OR REPLACE VIEW `conversations_themes_summary` AS
SELECT
  tbl_deleg.conversation_id AS conversation_id,
  tbl_deleg.id AS deleg_id,
  tbl_theme.id AS theme_id,
  tbl_theme.theme AS theme,
  tbl_state.id AS state_id,
  tbl_state.state AS state,
  tbl_deleg.lang AS lang
FROM `conversations_themes` AS tbl_deleg
LEFT JOIN `conversations_themes_state_latest` AS tbl_state_latest
  ON tbl_state_latest.deleg_id = tbl_deleg.id
LEFT JOIN `conversations_themes_states` AS tbl_state
  ON tbl_state.id = tbl_state_latest.state_id
LEFT JOIN `themes` AS tbl_theme
  ON tbl_theme.id = tbl_deleg.theme_id;
  ;

-- -----------------------------------------------------
-- View `ica`.`conversations_participants_summary`
