I have the following table:
--
-- Table structure for table `DESTINATIONS`
--
CREATE TABLE IF NOT EXISTS `DESTINATIONS` (
`DEST_ID` int(7) NOT NULL auto_increment,
`COUNT_ID` int(6) NOT NULL,
`REG_ID` int(6) NOT NULL,
`CITY_ID` int(6) NOT NULL,
`CREATE_DATE` datetime NOT NULL,
`DESTINATION` varchar(256) NOT NULL,
`APPROVED` tinyint(1) NOT NULL,
PRIMARY KEY (`DEST_ID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=192 ;
--
-- Dumping data for table `DESTINATIONS`
--
INSERT INTO `DESTINATIONS` (`DEST_ID`, `COUNT_ID`, `REG_ID`, `CITY_ID`, `CREATE_DATE`, `DESTINATION`, `APPROVED`)
VALUES (166, 9, 818, 0, '2011-10-27 15:24:20', 'Freeman\\''s Bay', 0);
And I am trying to run the following query:
SELECT *
FROM `DESTINATIONS`
WHERE `DESTINATION` LIKE '%Freeman\'s Bay%'
which is returning 0 results. However, stripping the LIKE clause to anything BEFORE the quote mark will find and return a match.
Obviously, I’m doing something wrong, but I haven’t been able to figure out what exactly. Can I not perform a SELECT LIKE this? Have I escaped the quotes incorrectly? Any input is appreciated!
The insert is escaped incorrectly. You are actually inserting the valueFreeman\'s Bay, including the\. The select is okay.The select is escaped incorrectly. You are have inserting the value
Freeman\'s Bay, but you’re looking forFreeman's Bay, excluding the\.