sql-like

Hibernate Criteria API condition “like” with integer

六眼飞鱼酱① 提交于 2019-12-24 07:17:13
问题 In my database I have a column "year" which is an integer. How can I search by using Criteria API (not by HQL) which records contain, for example "196..." in the year column? I think it should be Restrictions.like , but I got exception: SEVERE: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer 回答1: a better and faster solution would be to use Criterion.sqlRestriction(String sql). You can form the sql as, "to_char(year) like '19%'", be aware that to_char is

SQLl Like is not working string contain single quotes in php mysql

假装没事ソ 提交于 2019-12-24 07:01:06
问题 SQL LIKE is not working when string contains single quote ' , Below is my php code $keysearch = "St.Joseph's"; // Searching keyword containing single quotes $sql =mysqli_query("select id,name from tbl where name LIKE '%$keysearch%'"); It returns no result, How can I search a string contain single quotes? Is there any effective operator except 'LIKE' for comparing single quotes value in DB? 回答1: Use addslashes() function of PHP as below, $sql =mysqli_query($con,"select id,name from tbl where

MySQL: Optimizing Searches with LIKE or FULLTEXT

三世轮回 提交于 2019-12-24 04:46:07
问题 I am building a forum and I am looking for the proper way to build a search feature that finds users by their name or by the title of their posts. What I have come up with is this: SELECT users.id, users.user_name, users.user_picture FROM users, subject1, subject2 WHERE users.id = subject1.user_id AND users.id = subject2.user_id AND (users.user_name LIKE '%{$keywords}%' OR subject1.title1 LIKE '%{$keywords}%' OR subject2.title2 LIKE '%{$keywords}%') ORDER BY users.user_name ASC LIMIT 10

Using 'LIKE' operator with a subquery that returns multiple results

久未见 提交于 2019-12-24 01:14:33
问题 Newbie to SQL. Kindly help. I need to count number of records which have a pattern in one of the fields, for multiple patterns. I know how to do it for one pattern, but how do I get count of each pattern when there are multiple patterns coming from a subquery. I am using Oracle. I will try to explain with an example. SELECT count(*) FROM TableA WHERE TableA.comment LIKE '%world%'; Now this code will return the number of records which have 'world' anywhere in the TableA.comment field. My

Include space in mysql like search

假装没事ソ 提交于 2019-12-24 00:53:45
问题 I am having problem in using mysql like keyword in certain condition. My requirement goes like this. First, when i search for 'ABC' , the result should find ABC and ABCdef but not xyzABCdef or xyzABC . It seems simple at first to use ABC% . but in condition when i search for 'heart%' , it doesnot return row that have 'liver heart' because it returns only row that have heart at the beginning of the string.Then i tried using % heart% .This returned row having 'liver heart' but not those rows

Mysql update all columns starting with same Name

筅森魡賤 提交于 2019-12-24 00:43:59
问题 I have a dynamic table named 'products' with multiple Languages. The table columns looks like this: id, product_id, store_de, store_en, store_fr, store_es... etc The languages can be more or less. Now I want to update this table and set all columns beginning with "store_" to value 1. I tried the following: $stmt = $dbh->prepare( "UPDATE products SET `store_%` = ? WHERE product_id = ?" ); $stmt->execute( array( 1, $lastID ) ); I get following error message: SQLSTATE[42S22]: Column not found:

adding the value of a column into a LIKE statement?

那年仲夏 提交于 2019-12-24 00:09:10
问题 i have 3 tables for tags, tag categories and used tags. i'm wanting to get a list of all tags with a count of the used tags (the format of the tags used is comma separated values for each document id that has tags). i've been trying something like this but I can't get the value of the tags.tag field to be inserted into the LIKE statement. SELECT categories.category, tags.tag, (SELECT COUNT(id) FROM usedtags WHERE usedtags.value LIKE '%tags.tag%') as numtags FROM tags LEFT JOIN categories ON

Reverse version of sql LIKE in sqlalchemy [duplicate]

那年仲夏 提交于 2019-12-23 19:43:16
问题 This question already has an answer here : how to pass a not like operator in a sqlalchemy ORM query (1 answer) Closed 6 years ago . By "reverse version of like" I mean exactly like this question. The question is how to make a query like that in sqlalchemy? I found out that to make "SELECT LIKE" query in sqlalchemy I should make something like that session.query(Book).filter(Book.title.like("%"+my_title+"%")) Because like is method of column, I don't know how to use like method to ask about "

Select row which contains exact number in column with set of numbers separated by comma

北城以北 提交于 2019-12-23 16:27:05
问题 Maybe answer is very easy, but I can't find the right MySQL query which do what I want. I have table user : | id_user | name | action_type | +---------------------------------+ | 1 | joshua | 1,13,12,40 | | 2 | joshua | 2,8 | And I want to select only rows which have exact number in action_type column. action_type is stored in MySQL as TEXT. I've tried this: SELECT * FROM user WHERE action_type LIKE '%2%' But it selected rows with 12 which is not what I want :( Maybe it's possible with IN

How to search for “%” in sql table-column

折月煮酒 提交于 2019-12-23 15:34:03
问题 I have a table with a column "Remarks"...How to search "%" in this column? 回答1: Like this where Remarks like'%[%]%' you need to put brackets around it, more info here LIKE (Transact-SQL) 回答2: SELECT * FROM YourTable WHERE CHARINDEX('%', Remarks) > 0 回答3: there are 2 ways, you could use where Remarks like '%[%]%' or where Remarks like '%!%%' escape '!' 来源: https://stackoverflow.com/questions/6231744/how-to-search-for-in-sql-table-column