/*
SQLyog Ultimate
MySQL - 10.2.7-MariaDB : Database - bugTest
*********************************************************************
*/




CREATE DATABASE /*!32312 IF NOT EXISTS*/`bugTest` /*!40100 DEFAULT CHARACTER SET utf8 */;

USE `bugTest`;

/*Table structure for table `procViewTable` */


CREATE TABLE `procViewTable` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `subId` int(10) unsigned DEFAULT NULL,
  `someText` varchar(50) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;

/*Data for the table `procViewTable` */

insert  into `procViewTable`(`id`,`subId`,`someText`) values 
(1,NULL,'Test'),
(2,5,'Test 2'),
(3,8,'Test 3'),
(4,NULL,'Test 4');

/*Table structure for table `subProcViewTable` */


CREATE TABLE `subProcViewTable` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `someText` varchar(50) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=latin1;

/*Data for the table `subProcViewTable` */

insert  into `subProcViewTable`(`id`,`someText`) values 
(5,'Not a Test');

/* Procedure structure for procedure `procViewProcedure` */

/*!50003 DROP PROCEDURE IF EXISTS  `procViewProcedure` */;

DELIMITER $$

/*!50003 CREATE DEFINER=`procView`@`%` PROCEDURE `procViewProcedure`()
BEGIN
		SELECT * FROM `procViewSimple`;
	END */$$
DELIMITER ;

/* Function  structure for function  `procViewFunction` */

/*!50003 DROP FUNCTION IF EXISTS `procViewFunction` */;
DELIMITER $$

/*!50003 CREATE DEFINER=`procView`@`%` FUNCTION `procViewFunction`() RETURNS varchar(50) CHARSET latin1
BEGIN
		DECLARE `return` VARCHAR(50);
		SELECT `someText` INTO `return` FROM `procViewSimple` LIMIT 1;
		RETURN `return`;
	END */$$
DELIMITER ;

/*Table structure for table `procViewSimple` */


/*!50001 DROP VIEW IF EXISTS `procViewSimple` */;
/*!50001 DROP TABLE IF EXISTS `procViewSimple` */;

/*!50001 CREATE TABLE  `procViewSimple`(
 `id` int(10) unsigned ,
 `currentStatus` varchar(50) 
)*/;

/*View structure for view procViewSimple */

/*!50001 DROP TABLE IF EXISTS `procViewSimple` */;
/*!50001 DROP VIEW IF EXISTS `procViewSimple` */;

/*!50001 CREATE ALGORITHM=UNDEFINED DEFINER=`procView`@`%` SQL SECURITY DEFINER VIEW `procViewSimple` AS (select `innerQuery`.`id` AS `id`,`innerQuery`.`someText` AS `someText` from (select `bugTest`.`procViewTable`.`id` AS `id`,`bugTest`.`procViewTable`.`someText` AS `someText` from `bugTest`.`procViewTable`) `innerQuery` group by `innerQuery`.`id`) */;

