sql-like

SQL LIKE % inside array

◇◆丶佛笑我妖孽 提交于 2019-11-26 20:11:26
问题 I know how to perform an SQL LIKE % query for a single value like so: SELECT * FROM users WHERE name LIKE %tom%; but how do I do this if the search terms for my LIKE comes from an array? For example, let's say we have an array like this: $words = array("Tom", "Smith", "Larry"); How do I perform my SQL LIKE % to search for the words in my array like: SELECT * FROM users WHERE name LIKE %[each_element_from_my_array]% WITHOUT putting the whole query inside a foreach loop or something EDIT : I

Using Eloquent ORM in Laravel to perform search of database using LIKE

痞子三分冷 提交于 2019-11-26 19:13:21
问题 I want to use Eloquent's active record building to build a search query, but it is going to be a LIKE search. I have found the User::find($term) or User::find(1) , but this is not generating a like statement. I'm not looking for a direct answer, but if someone could at least give me a direction to look in that'd be great! 回答1: You're able to do database finds using LIKE with this syntax: Model::where('column', 'LIKE', '%value%')->get(); 回答2: If you need to frequently use LIKE, you can

How do you force mysql LIKE to be case sensitive? [duplicate]

这一生的挚爱 提交于 2019-11-26 18:59:07
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: Mysql Like Case Sensitive Mysql ignores case for its LIKE comparisons. How can you force it to perform case-sensitive LIKE comparisons? 回答1: Use LIKE BINARY : mysql> SELECT 'abc' LIKE 'ABC'; -> 1 mysql> SELECT 'abc' LIKE BINARY 'ABC'; -> 0 回答2: Another alternative is to use COLLATE , SELECT * FROM table1 WHERE columnName like 'a%' COLLATE utf8_bin; SQLFiddle Demo 来源: https://stackoverflow.com/questions/14007450

Parameter in like clause JPQL

我的梦境 提交于 2019-11-26 18:43:46
I am trying to write a JPQL query with a like clause: LIKE '%:code%' I would like to have code=4 and find 455 554 646 ... I cannot pass :code = '%value%' namedQuery.setParameter("%" + this.value + "%"); because in another place I need :value not wrapped by the % chars. Any help? If you do LIKE :code and then do namedQuery.setParameter("code", "%" + this.value + "%"); Then value remains free from the '%' sign. If you need to use it somewhere else in the same query simply use another parameter name other than 'code' . I don't use named parameters for all queries. For example it is unusual to use

PHP PDO MySQL query LIKE -> multiple keywords

你离开我真会死。 提交于 2019-11-26 18:40:16
问题 I have a users table in MySQL and would like a search by name. Right now I have the following code: <?php $search = @$_GET['q']; $search = strtoupper($search); $search = strip_tags($search); $search = trim($search); $query = $con->prepare('SELECT * FROM `users` WHERE name LIKE ?'); $query->execute(array('%'.$search.'%')); $result = $query->rowCount(); echo $result; ?> The problem is that I want to have multiple keywords. Let's say someone types "Here should be a nice name of a person" then it

SQLite accent-insensitive search

爷,独闯天下 提交于 2019-11-26 17:50:14
问题 Is there any way to do an accent-insensitive LIKE query in SQLite? For example, this query: SELECT * FROM users WHERE name LIKE "Andre%" would return: André the Giant Andre Agassi etc. I'm using Qt with QSqlDatabase if it makes any difference. 回答1: Set up a collation using sqlite3_create_collation and then use it like this: SELECT * FROM users WHERE name LIKE "Andre%" COLLATE NOACCENTS 来源: https://stackoverflow.com/questions/14009261/sqlite-accent-insensitive-search

MySQL Like multiple values

不打扰是莪最后的温柔 提交于 2019-11-26 17:00:46
I have this MySQL query. I have database fields with this contents sports,shopping,pool,pc,games shopping,pool,pc,games sports,pub,swimming, pool, pc, games Why does this like query does not work? I need the fields with either sports or pub or both? SELECT * FROM table WHERE interests LIKE ('%sports%', '%pub%') The (a,b,c) list only works with in . For like , you have to use or : WHERE interests LIKE '%sports%' OR interests LIKE '%pub%' Faster way of doing this: WHERE interests LIKE '%sports%' OR interests LIKE '%pub%' is this: WHERE interests REGEXP 'sports|pub' Found this solution here: http

SQLite query, 'LIKE'

狂风中的少年 提交于 2019-11-26 16:35:10
问题 I am trying to retrieve information from my database. I have words like Lim Won Mong and Limited . If I do my query, SELECT name FROM memberdb WHERE name LIKE '%LIM%' , it displays both Lim Won Mong and Limited and I only want data from Lim Won Mong . How should I rewrite my query? 回答1: Execute following Query: select name from memberdb where name like '% LIM %' OR name like "LIM %" OR name like "% LIM" OR name like "LIM" 回答2: If you want to match the word "lim" (so it matches "a lim", "lim a

implement LIKE query in PDO

萝らか妹 提交于 2019-11-26 15:20:51
I am running problems in implementing LIKE in PDO I have this query: $query = "SELECT * FROM tbl WHERE address LIKE '%?%' OR address LIKE '%?%'"; $params = array($var1, $var2); $stmt = $handle->prepare($query); $stmt->execute($params); I checked the $var1 and $var2 they contain both the words I want to search, my PDO is working fine since some of my queries SELECT INSERT they work, it's just that I am not familiar in LIKE here in PDO. The result is none returned. Do my $query is syntactically correct? You have to include the % signs in the $params , not in the query: $query = "SELECT * FROM

Element or class LIKE selector for jQuery?

回眸只為那壹抹淺笑 提交于 2019-11-26 15:15:30
问题 For whatever reason I have these classes called .main_sub1 , .main_sub2 etc. Never mind why I can't have .main .sub . Is there a way with jQuery, sort of in the way it is possible to do with attributes, to get the classes containing main ? 回答1: Using $("[class^=main]") will select all elements whose classname starts with 'main'. Take a look at jQuery docs about selectors, there are a lot of other variations you can use, for example: [class*=main] will select elements whose classname contains