sql-like

LIKE wildcard with multiple fields and spaces in MYSQL

China☆狼群 提交于 2019-12-05 07:51:38
I'm having some trouble searching for any similar match in two fields. For example I have a table with the values: CAR MAKE CAR MODEL Ford Mustang (Shelby) Toyota Corolla Seat Leon etc etc. I want to be able to get the result "Ford, Mustang (Shelby)" by searching for any of the following combinations: Ford Mustang Shelby Ford Mustang or any other combination. Is this possible? I've had a good search but it's hard to find the search terms to describe what I mean. Split your terms on whitespace and then, for each term, build a little bit of SQL like this: car_make like '%x%' or car_model like '

T-SQL speed comparison between LEFT() vs. LIKE operator

孤人 提交于 2019-12-05 00:08:07
I'm creating result paging based on first letter of certain nvarchar column and not the usual one, that usually pages on number of results. And I'm not faced with a challenge whether to filter results using LIKE operator or equality ( = ) operator. select * from table where name like @firstletter + '%' vs. select * from table where left(name, 1) = @firstletter I've tried searching the net for speed comparison between the two, but it's hard to find any results, since most search results are related to LEFT JOINs and not LEFT function. Your best bet would be to measure the performance on real

PHP PDO LIKE : escaping the % character when combining with wildcard

人盡茶涼 提交于 2019-12-04 16:41:47
$percent = ‘%’; $st=$db->prepare(“SELECT * FROM x WHERE y LIKE ?”); $st=$st->execute(array(‘%’.$percent.’%’)); /*I want to get all records with the string % included like 5% etc.*/ The above example will not match correctly, instead matching all records in table x. In order for this to work correctly, I apparently need to set $percent='\%'. This is where I am left confused about the concept behind prepared statements. I thought the whole point of prepared statements was that the value itself( $percent) would simply be interpreted as a string instead of a special wildcard character. I would

SWITCH with LIKE inside SELECT query in MySQL

烂漫一生 提交于 2019-12-04 15:17:27
问题 I have this Tags table CREATE TABLE IF NOT EXISTS `Tags` ( `id_tag` int(10) unsigned NOT NULL auto_increment, `tag` varchar(255) default NULL, PRIMARY KEY (`id_tag`), UNIQUE KEY `tag` (`tag`), KEY `id_tag` (`id_tag`), KEY `tag_2` (`tag`), KEY `tag_3` (`tag`), KEY `tag_4` (`tag`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2937 ; INSERT INTO `Tags` (`id_tag`, `tag`) VALUES (1816, '(class'), (2642, 'class\r\n\r\nâ?¬35'), (1906, 'class\r\nif'), (1398, 'class'), (2436, 'class)'), (1973,

NOT LIKE and LIKE not returning opposite result

不羁的心 提交于 2019-12-04 14:55:09
问题 I have a table with 200 records out of which 10 records has text containing the word 'TAX'. When I'm executing Select * from tbl1 WHERE [TextCol] LIKE '%TAX%' then I get the result set with those 10 records correctly . But when I am trying to exclude those records by Select * from tbl1 WHERE [TextCol] NOT LIKE '%TAX%' it's returning 100 records only, instead of 190. 回答1: Does this return the correct result ? Select * from tbl1 WHERE COALESCE([TextCol],'-1') NOT LIKE '%TAX%' I believe NULL

MySQL exact word existence check in a table Field

别说谁变了你拦得住时间么 提交于 2019-12-04 12:29:36
I've a Query. Is there any built-in function or any other method associated with MySQL, which will return rows that contains EXACT word in the database table field? I'm aware that with MySQL LIKE operator, You can search for a specified pattern in a column which will match a string value against a pattern string containing wild-card characters. But With MySQL LIKE clause, It'll return substring entries too. Eg. Suppose 3 column values are like below: 1. "Take another shot of courage" 2. "The End of This age is Not Yet" 3. "Employers can obtain this wage rate by submitting a request" I want to

HQL like operator for case insensitive search

不羁的心 提交于 2019-12-04 08:57:53
问题 I am implementing an autocomplete functionality using Jquery, when I type the name, it fetches the record from the db, The records stored in db are mixture of capital & small letters. I have written a HQL Query which fetches me the records with case-sensitive, but I need to records irrespective of case. Here is the query, List<OrganizationTB> resultList = null; Query query = session.createQuery("from DataOrganization dataOrg where dataOrg.poolName like '%"+ poolName +"%'"); resultList = query

PostgreSQL performance difference between LIKE and regex

孤者浪人 提交于 2019-12-04 05:14:43
Could someone explain such a big performance difference between these SQLs ? SELECT count(*) as cnt FROM table WHERE name ~ '\*{3}'; -- Total runtime 12.000 - 18.000 ms SELECT count(*) as cnt FROM table WHERE name ~ '\*\*\*'; -- Total runtime 12.000 - 18.000 ms SELECT count(*) as cnt FROM table WHERE name LIKE '%***%'; -- Total runtime 5.000 - 7.000 ms As you can see, the difference is more than double between LIKE operator and simple regular expression (I thought LIKE operator internally would be converted into the regular expression and there shouldn't be any difference) There are almost

T-SQL special characters to escape for LIKE operator wildcard search

青春壹個敷衍的年華 提交于 2019-12-04 05:04:59
SQL Server has the LIKE operator to handle wildcard searches. My customer wants to use the "*" (asterisk) character in the user interface of an application as the wildcard character. I'm just wondering if there are any standard characters that I need to worry about (that are used as special characters in SQL Server) besides the "%" (percent) character itself before performing a LIKE wilcard search in case their keyword contains a "%" and needs to find a "%" in the actual string. If so, what are they? So please assume that [table1].[column1] will never have a "*" (asterisk) in the text string!

Slow search by index query LIKE% MYSQL

假如想象 提交于 2019-12-04 03:31:55
问题 i have table with 100 000 000 rows so large. Structure of table id int INDEX(not primary not unique just index) lang_index varchar(5) INDEX name varchar(255) INDEX enam varchar(255) INDEX Ok. i do query 1 Query "SELECT name FROM table WHERE lang_index='en' AND name LIKE 'myname%'" Speed is ok for this large table. around 0.02 sec. i try 2 Query "SELECT name FROM table WHERE lang_index='en' AND (name LIKE 'myname%' OR enam LIKE 'myname%')" Very very slow around 230 sec!!! then i try this 3