Using OR in LIKE Query in MySQL to compare multiple fields
Use this:: SELECT * FROM MyTable WHERE (Column1 LIKE ‘%keyword1%’ OR Column2 LIKE ‘%keyword1%’) AND (Column1 LIKE ‘%keyword2%’ OR Column2 LIKE ‘%keyword2%’);
Use this:: SELECT * FROM MyTable WHERE (Column1 LIKE ‘%keyword1%’ OR Column2 LIKE ‘%keyword1%’) AND (Column1 LIKE ‘%keyword2%’ OR Column2 LIKE ‘%keyword2%’);
Execute following Query: select name from memberdb where name like ‘% LIM %’ OR name like “LIM %” OR name like “% LIM” OR name like “LIM”
Change your query to this: Query qry = session.createQuery(“From RegistrationBean as rb where rb.”+searchCriteria+” like ?”); qry.setString(0, “%”+searchField+”%”);
Use LIKE BINARY: mysql> SELECT ‘abc’ LIKE ‘ABC’; -> 1 mysql> SELECT ‘abc’ LIKE BINARY ‘ABC’; -> 0
Given the sample data, I suspect you have control characters in your data. For example char(13), char(10) To confirm this, just run the following Select customerid,phone From YourTable Where CharIndex(CHAR(0),[phone])+CharIndex(CHAR(1),[phone])+CharIndex(CHAR(2),[phone])+CharIndex(CHAR(3),[phone]) +CharIndex(CHAR(4),[phone])+CharIndex(CHAR(5),[phone])+CharIndex(CHAR(6),[phone])+CharIndex(CHAR(7),[phone]) +CharIndex(CHAR(8),[phone])+CharIndex(CHAR(9),[phone])+CharIndex(CHAR(10),[phone])+CharIndex(CHAR(11),[phone]) +CharIndex(CHAR(12),[phone])+CharIndex(CHAR(13),[phone])+CharIndex(CHAR(14),[phone])+CharIndex(CHAR(15),[phone]) +CharIndex(CHAR(16),[phone])+CharIndex(CHAR(17),[phone])+CharIndex(CHAR(18),[phone])+CharIndex(CHAR(19),[phone]) +CharIndex(CHAR(20),[phone])+CharIndex(CHAR(21),[phone])+CharIndex(CHAR(22),[phone])+CharIndex(CHAR(23),[phone]) +CharIndex(CHAR(24),[phone])+CharIndex(CHAR(25),[phone])+CharIndex(CHAR(26),[phone])+CharIndex(CHAR(27),[phone]) +CharIndex(CHAR(28),[phone])+CharIndex(CHAR(29),[phone])+CharIndex(CHAR(30),[phone])+CharIndex(CHAR(31),[phone]) +CharIndex(CHAR(127),[phone]) >0 If the Test Results are Positive The following UDF can be used to strip the control … Read more
Set up a collation using sqlite3_create_collation and then use it like this: SELECT * FROM users WHERE name LIKE “Andre%” COLLATE NOACCENTS
Using INSTR: SELECT * FROM TABLE a JOIN TABLE b ON INSTR(b.column, a.column) > 0 Using LIKE: SELECT * FROM TABLE a JOIN TABLE b ON b.column LIKE ‘%’+ a.column +’%’ Using LIKE, with CONCAT: SELECT * FROM TABLE a JOIN TABLE b ON b.column LIKE CONCAT(‘%’, a.column ,’%’) Mind that in all options, you’ll … Read more
In general, there is a tradeoff between “precision” and “recall”. High precision means that fewer irrelevant results are presented (no false positives), while high recall means that fewer relevant results are missing (no false negatives). Using the LIKE operator gives you 100% precision with no concessions for recall. A full text search facility gives you … Read more
Those queries all appear to be vulnerable to SQL injection attacks. Try something like this instead: curs.execute(“””SELECT tag.userId, count(user.id) as totalRows FROM user INNER JOIN tag ON user.id = tag.userId WHERE user.username LIKE %s”””, (‘%’ + query + ‘%’,)) Where there are two arguments being passed to execute().
What would be useful here would be a LIKE ANY predicate as is available in PostgreSQL SELECT * FROM tbl WHERE my_col LIKE ANY (ARRAY[‘%val1%’, ‘%val2%’, ‘%val3%’, …]) Unfortunately, that syntax is not available in Oracle. You can expand the quantified comparison predicate using OR, however: SELECT * FROM tbl WHERE my_col LIKE ‘%val1%’ OR … Read more