 USE `ica`;
 CREATE  OR REPLACE VIEW `jointsources_state_latest` AS
 SELECT
-	tbl_state.jointsource_id AS jointsource_id,
-	MAX(tbl_state.id) AS state_id
+  tbl_state.jointsource_id AS jointsource_id,
+  MAX(tbl_state.id) AS state_id
 FROM `jointsources_states` AS tbl_state
 GROUP BY jointsource_id;
 

USE `ica`;
CREATE  OR REPLACE VIEW `jointsources_summary` AS
SELECT
	tbl_jointsource.id AS jointsource_id,
	tbl_jointsource.type AS jointsource_type,
	tbl_state.id AS state_id,
	tbl_state.state AS state
FROM `jointsources` AS tbl_jointsource
LEFT JOIN `jointsources_state_latest` AS tbl_state_latest
	ON tbl_state_latest.jointsource_id = tbl_jointsource.id
LEFT JOIN `jointsources_states` AS tbl_state
	ON tbl_state.id = tbl_state_latest.state_id;

-- -----------------------------------------------------
-- View `ica`.`discussions_summary`

USE `ica`;
CREATE  OR REPLACE VIEW `contents_langs_rev_latest` AS
SELECT
  tbl_rev.lang_id AS lang_id,
  MAX(tbl_rev.id) AS rev_id
FROM `contents_langs_revs` AS tbl_rev
GROUP BY lang_id;

