Description:
when deleting from a view select error, all table is being deleted
How to repeat:
-- phpMyAdmin SQL Dump
-- version 4.3.11
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: 05-Maio-2017 às 16:40
-- Versão do servidor: 5.6.24
-- PHP Version: 5.5.24
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
--
-- Database: `bug`
--
-- --------------------------------------------------------
--
-- Stand-in structure for view `duplicados`
--
CREATE TABLE IF NOT EXISTS `duplicados` (
`max(id)` int(11)
,`nome` varchar(50)
);
-- --------------------------------------------------------
--
-- Estrutura da tabela `nomes`
--
CREATE TABLE IF NOT EXISTS `nomes` (
`id` int(11) NOT NULL,
`nome` varchar(50) NOT NULL,
`data` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8;
--
-- Extraindo dados da tabela `nomes`
--
INSERT INTO `nomes` (`id`, `nome`, `data`) VALUES
(1, 'marcelo', '2017-05-05 19:26:37'),
(2, 'igor', '2017-05-05 19:26:37'),
(3, 'morte', '2017-05-05 19:26:37'),
(4, 'janaina', '2017-05-05 19:26:37'),
(5, 'marcele', '2017-05-05 19:26:37'),
(6, 'bruno', '2017-05-05 19:26:37'),
(7, 'leo', '2017-05-05 19:26:37'),
(8, 'walisson', '2017-05-05 19:26:37'),
(9, 'pedro', '2017-05-05 19:26:37'),
(10, 'patricia', '2017-05-05 19:26:37'),
(11, 'leo', '2017-05-05 19:26:37'),
(12, 'marcelo', '2017-05-05 19:26:37'),
(13, 'rosana', '2017-05-05 19:26:37'),
(14, 'janaina', '2017-05-05 19:26:37'),
(15, 'pedro', '2017-05-05 19:26:37'),
(16, 'marina', '2017-05-05 19:26:37'),
(17, 'mariana', '2017-05-05 19:26:37'),
(18, 'brun', '2017-05-05 19:26:37'),
(19, 'walisson', '2017-05-05 19:26:37'),
(20, 'marcele', '2017-05-05 19:26:37');
-- --------------------------------------------------------
--
-- Structure for view `duplicados`
--
DROP TABLE IF EXISTS `duplicados`;
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `duplicados` AS select max(`nomes`.`id`) AS `max(id)`,`nomes`.`nome` AS `nome` from `nomes` group by `nomes`.`nome` having (count(0) >= 2) order by `nomes`.`nome`;
--
-- Indexes for dumped tables
--
--
-- Indexes for table `nomes`
--
ALTER TABLE `nomes`
ADD PRIMARY KEY (`id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `nomes`
--
ALTER TABLE `nomes`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=21;
delete from nomes where id in (select id from duplicados);
Suggested fix:
should report error, cause ID is not a valid field name, but it delete all table NOMES