SQL Join on a column LIKE another column [duplicate]
You only need to concatenate the strings, you could also do a search and replace. SELECT a.first_name, b.age FROM names a JOIN ages b ON b.full_name LIKE ‘%’ + a.first_name + ‘%’
You only need to concatenate the strings, you could also do a search and replace. SELECT a.first_name, b.age FROM names a JOIN ages b ON b.full_name LIKE ‘%’ + a.first_name + ‘%’
SELECT Id, Url, ModelId WHERE Url LIKE CONCAT(‘%’, ModelId, ‘%’)
You can use the Series method str.startswith (which takes a regex): In [11]: s = pd.Series([‘aa’, ‘ab’, ‘ca’, np.nan]) In [12]: s.str.startswith(‘a’, na=False) Out[12]: 0 True 1 True 2 False 3 False dtype: bool You can also do the same with str.contains (using a regex): In [13]: s.str.contains(‘^a’, na=False) Out[13]: 0 True 1 True 2 … Read more
Do you just want to search on word boundaries? If so a crude version might be: SELECT * FROM products WHERE product_name LIKE “% foo %”; Or you could be a bit cleverer and look for word boundaries with the following REGEXP SELECT * FROM products WHERE product_name RLIKE “[[:<:]]foo[[:>:]]”;
If you want a % symbol in search_criteria to be treated as a literal character rather than as a wildcard, escape it to [%] … where name like ‘%’ + replace(search_criteria, ‘%’, ‘[%]’) + ‘%’
A much better solution in terms of performance: SELECT …. FROM …. WHERE `concatenated` LIKE BINARY ‘%SearchTerm%’; String comparision is case-sensitive when any of the operands is a binary string. Another alternative is to use COLLATE, SELECT …. FROM …. WHERE `concatenated` like ‘%SearchTerm%’ COLLATE utf8_bin;
FULLTEXT searches are absolutely going to be faster, as kibibu noted in the comments above. However: mysql> select COUNT(ID) FROM table WHERE INSTR(Name,’search’) > 0; +———–+ | COUNT(ID) | +———–+ | 40735 | +———–+ 1 row in set (5.54 sec) mysql> select COUNT(ID) FROM table WHERE Name LIKE ‘%search%’; +———–+ | COUNT(ID) | +———–+ | … Read more
If WPP.COMMENT contains NULL, the condition will not match. This query: SELECT 1 WHERE NULL NOT LIKE ‘%test%’ will return nothing. On a NULL column, both LIKE and NOT LIKE against any search string will return NULL. Could you please post relevant values of a row which in your opinion should be returned but it … Read more
You have to include the % signs in the $params, not in the query: $query = “SELECT * FROM tbl WHERE address LIKE ? OR address LIKE ?”; $params = array(“%$var1%”, “%$var2%”); $stmt = $handle->prepare($query); $stmt->execute($params); If you’d look at the generated query in your previous code, you’d see something like SELECT * FROM tbl … Read more
Full Text Searching (using the CONTAINS) will be faster/more efficient than using LIKE with wildcarding. Full Text Searching (FTS) includes the ability to define Full Text Indexes, which FTS can use. I don’t know why you wouldn’t define a FTS index if you intended to use the functionality. LIKE with wildcarding on the left side … Read more