考虑这个查询(演示在这里)
(SELECT * FROM `titles` where title = 'test\\')
UNION ALL
(SELECT * FROM `titles` where title LIKE 'test\\\\')
输出:
| ID | TITLE |
--------------
| 1 | test\ |
| 1 | test\ |
问题:
为什么(=)不需要额外的(\)而 (like) 需要额外的\\?很明显,MySQL用(test\\)转义了(test\ )然后使用(test\\\\)对于 LIKE 是合乎逻辑的。
表信息:
CREATE TABLE IF NOT EXISTS `titles` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;
--
-- Dumping data for table `titles`
--
INSERT INTO `titles` (`id`, `title`) VALUES
(1, 'test\\');