I just want a select query where it can Select all user uid who have born after 1986 Year.
I tried this query but it only selects the matching number LIKE
search.
SELECT uid FROM {profile_values} WHERE value LIKE '%1986%'
Here is the SQL query
CREATE TABLE IF NOT EXISTS `profile_values` (
`fid` int(10) unsigned NOT NULL DEFAULT '0',
`uid` int(10) unsigned NOT NULL DEFAULT '0',
`value` text,
PRIMARY KEY (`uid`,`fid`),
KEY `fid` (`fid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `profile_values` (`fid`, `uid`, `value`) VALUES
(5, 1, 'a:3:{s:3:"day";s:2:"27";s:5:"month";s:1:"6";s:4:"year";s:4:"1986";}'),
(5, 3, 'a:3:{s:3:"day";s:2:"15";s:5:"month";s:1:"9";s:4:"year";s:4:"1910";}'),
(5, 4, 'a:3:{s:3:"day";s:2:"26";s:5:"month";s:1:"6";s:4:"year";s:4:"1986";}'),
(5, 5, 'a:3:{s:5:"month";s:1:"4";s:3:"day";s:2:"26";s:4:"year";s:4:"2014";}'),
(5, 6, 'a:3:{s:3:"day";s:2:"26";s:5:"month";s:1:"4";s:4:"year";s:4:"2014";}'),
(5, 7, 'a:3:{s:5:"month";s:1:"4";s:3:"day";s:2:"26";s:4:"year";s:4:"2014";}'),
(5, 8, 'a:3:{s:3:"day";s:2:"26";s:5:"month";s:1:"4";s:4:"year";s:4:"1987";}'),
(5, 17, 'N;'),
(5, 18, 'N;'),
You can try REGEXP. The REGEXP matching condition is similar to the LIKE but LIKE only performs simple pattern matching using the wildcards "%" and "_", REGEXP performs complex regular expression pattern matching allowing it to match a much greater range of string patterns than LIKE.
SELECT uid FROM {profile_values}
WHERE value REGEXP '[1][9][8][6-9]|[1][9][9][0-9]|[2-9][0-9][0-9][0-9]';
Well here we make sure that our expression considers only 4 digit number and moreover number should be greater than 1986
so [1][9][8][6-9] -->> makes sure number is between 1986 to 1989
next [1][9][9][0-9] -->> makes sure number is between 1990 to 1999
last [2-9][0-9][0-9][0-9] -->> makes sure number is between 2000 to 9999
please refer http://www.tutorialspoint.com/mysql/mysql-regexps.htm for more
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.