DROP TABLE IF EXISTS `v_category2`;
DROP VIEW IF EXISTS `v_category2`;

CREATE OR REPLACE VIEW `_db_study`.`v_category2` AS 
SELECT m_category2.*, 
m_category.c_categoryName, m_category.c_categoryDisplayOrder
FROM m_category2
LEFT OUTER JOIN m_category ON m_category2.id_category = m_category.id_category
WHERE m_category2.c_delete = 0;

DROP TABLE IF EXISTS `v_category_valid`;
DROP VIEW IF EXISTS `v_category_valid`;

CREATE OR REPLACE VIEW `_db_study`.`v_category_valid` AS 
SELECT distinct m_category.id_category, m_category.c_categoryName, m_category.c_categoryDisplayOrder, m_category.c_delete
FROM m_category
JOIN m_category2 ON m_category.id_category = m_category2.id_category
WHERE m_category.c_delete = 0;




DROP TABLE IF EXISTS `v_study`;
DROP VIEW IF EXISTS `v_study`;

CREATE OR REPLACE VIEW `_db_study`.`v_study` AS 
SELECT m_study.*,
v_category2.id_category,
v_category2.c_categoryName, v_category2.c_categoryDisplayOrder,
v_category2.c_category2Name, v_category2.c_category2DisplayOrder
FROM m_study
LEFT OUTER JOIN v_category2 ON m_study.id_category2 = v_category2.id_category2
WHERE m_study.c_delete = 0;




DROP TABLE IF EXISTS `v_mycheck`;
DROP VIEW IF EXISTS `v_mycheck`;

CREATE OR REPLACE VIEW `_db_study`.`v_mycheck` AS 
SELECT m_mycheck.id_mycheck, m_mycheck.id_account, m_mycheck.c_check,
m_mycheck.c_registtime, m_mycheck.c_updatetime,
v_study.id_study, v_study.c_question,v_study.c_answer,
v_study.c_categoryName, v_study.c_categoryDisplayOrder,
v_study.c_category2Name, v_study.c_category2DisplayOrder
FROM m_mycheck
RIGHT OUTER JOIN v_study ON m_mycheck.id_study = v_study.id_study;
