Skip to content

Tarik Billa

  • Web Development
    • html
    • vue.js
    • laravel
    • css
    • javascript
    • jquery
    • node.js
    • php
    • asp.net
  • Programming
    • python
    • java
    • c
    • c++
    • c#
  • git
  • android

sql-like

SQL Join on a column LIKE another column [duplicate]

August 20, 2023 by Tarik

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 + ‘%’

Categories mysql Tags join, mysql, sql, sql-like Leave a comment

MySQL like another field

August 19, 2023 by Tarik

SELECT Id, Url, ModelId WHERE Url LIKE CONCAT(‘%’, ModelId, ‘%’)

Categories mysql Tags mysql, sql-like Leave a comment

Pandas text matching like SQL’s LIKE?

August 14, 2023 by Tarik

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

Categories pandas Tags pandas, sql-like, string-matching Leave a comment

MySQL – How to search for exact word match using LIKE?

August 13, 2023 by Tarik

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[[:>:]]”;

Categories mysql Tags mysql, select, sql, sql-like Leave a comment

SQL ‘LIKE’ query using ‘%’ where the search criteria contains ‘%’

August 7, 2023 by Tarik

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, ‘%’, ‘[%]’) + ‘%’

Categories sql Tags sql, sql-like, sql-server Leave a comment

Like Case Sensitive in MySQL

August 7, 2023 by Tarik

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;

Categories mysql Tags case-sensitive, mysql, sql-like Leave a comment

Which is faster — INSTR or LIKE?

June 12, 2023 by Tarik

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

Categories mysql Tags mysql, sql-like Leave a comment

SQL Not Like Statement not working

May 26, 2023 by Tarik

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

Categories sql Tags sql, sql-like, where-clause Leave a comment

implement LIKE query in PDO

May 25, 2023 by Tarik

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

Categories php Tags mysql, pdo, php, sql-like Leave a comment

Performance of like ‘%Query%’ vs full text search CONTAINS query

May 23, 2023 by Tarik

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

Categories sql Tags database, full-text-search, performance, sql, sql-like Leave a comment
Older posts
Newer posts
← Previous Page1 Page2 Page3 … Page7 Next →

Tarik Billa

Software Engineer
tarikbilla@gmail.com
+8801884414000
  • Reuse a hash in YAMLApril 17, 2024
  • Dockerfile: how to redirect the output of a RUN command to a variable?April 16, 2024
  • How to cd to a directory with spaces in the directory name?April 16, 2024
  • Maximum MIME type length when storing the type in a databaseApril 16, 2024
  • What is the difference between Unit, Integration, Regression and Acceptance Testing?April 16, 2024
© 2026 Tarik Billa