sql-like

MySQL exact word existence check in a table Field

那年仲夏 提交于 2019-12-06 08:13:59
问题 I've a Query. Is there any built-in function or any other method associated with MySQL, which will return rows that contains EXACT word in the database table field? I'm aware that with MySQL LIKE operator, You can search for a specified pattern in a column which will match a string value against a pattern string containing wild-card characters. But With MySQL LIKE clause, It'll return substring entries too. Eg. Suppose 3 column values are like below: 1. "Take another shot of courage" 2. "The

mysql search for a catid in a text field

半腔热情 提交于 2019-12-06 07:26:59
I'm trying to do a mysql search (in php) for a catid number within a text field. I'm currently using LIKE but I need it more specific. Here's my code: SELECT * FROM articlepix WHERE published = 1 AND catid LIKE '%86%' ORDER BY RAND() LIMIT 1 ^^ I'm looking for the number 86 within the catid field, but I want it to look for only 86, currently it's pulling out the data with the number 186 too. The above example grabs the field where the catid is "91,107,36,139,146,168,186". Is it possible to search for just '86' rather than everything that includes %86%? If that makes sense? MySQL can help you

CREATE TABLE new_table_name LIKE old_table_name with old_table_name's AUTO_INCREMENT values

最后都变了- 提交于 2019-12-06 06:57:50
Can I create a new table with an old table's autoincriment status in mysql client? I think, that ALTER TABLE new_table_name AUTO_INCREMENT=@my_autoincr_iment helps me, but this construction must use with a constant value. I don't want to use a difficult script. mysql> create table new_table like old_table; mysql> select @my_auto_increment:=auto_increment from information_schema.tables where table_name='old_table'; mysql> set @query = CONCAT("alter table new_table auto_increment = ", @my_auto_increment); mysql> prepare stmt from @query; mysql> execute stmt; mysql> deallocate prepare stmt; Thx

How to add case statement to add break after every record?

依然范特西╮ 提交于 2019-12-06 06:06:20
There should be a break after every row LIKE 'A%' when find next records of LIKE 'B%' . $stmt = $con->prepare("SELECT * FROM fistevent WHERE Event_Id=? AND TicketType=? AND row_name REGEXP '^[A-Z]' ORDER BY row_name ASC"); $stmt->bind_param("ss", $_POST['EventId'],$_POST['TicketType']); $stmt->execute(); $result = $stmt->get_result(); $numRows = $result->num_rows; if($numRows > 0) { echo ' <div class="register">'; while($r = $result->fetch_assoc()) { $EvntId = $r['Event_Id']; $RowName = $r['row_name']; echo '<ul id="sub" class="sub">'; if($r['seats'] == null){ echo '<li class="BlankSeat" ></li

Repeating characters in T-SQL LIKE condition

浪子不回头ぞ 提交于 2019-12-06 02:02:59
Problem: Limit the value of a VARCHAR variable (or a column) to digits and ASCI characters, but allow variable length. This script will not yield required result: declare @var as VARCHAR (150) select @var = '123ABC' if (@var LIKE '[a-zA-Z0-9]{0,150}') print 'OK' else print 'Not OK' Anyone have idea how to do this? You can do this with the not carat ^, and a NOT LIKE expression. So you say, where not like not non-alphanumeric ;) This works for standard numbers & characters: declare @var as VARCHAR (150) select @var = '123ABC' if (@var NOT LIKE '%[^a-zA-Z0-9]%') print 'OK' else print 'Not OK'

PHP way to execute SQL LIKE matching without a database query?

大兔子大兔子 提交于 2019-12-05 21:05:18
I want to match an input string to my PHP page the same way a match done by the LIKE command in SQL (MySQL) for consistency of other searches. Since (I have seen but don't comprehend) some of the PHP syntax includes SQL commands I am wondering if this is possible? The reason for this is I am now implementing a search of a keyword versus fields in the DB that are stored in a serialized array, which I have to unserialize in PHP and search depending on the structure of the array. I can't query against the table, just need the matching ability of the query. Otherwise I need to find an alternate

How to SELECT using both wildcards (LIKE) and array (IN)?

ぃ、小莉子 提交于 2019-12-05 12:33:07
问题 In SQL, if you want to perform a SELECT with a wildcard, you'd use: SELECT * FROM table_name WHERE field_name LIKE '%value%' If you wanted to use an array of possible values, you'd use: SELECT * FROM table_name WHERE field_name IN ('one', 'two', 'three') But, what would you do if you wanted to use both wildcards AND an array? Kind of like: SELECT * FROM table_name WHERE field_name LIKE IN ('%one', '_two', 'three[abv]') 回答1: SELECT * FROM table_name WHERE field_name LIKE '%one' OR field_name

How can you find a literal percent sign (%) in PostgreSQL using a LIKE query?

亡梦爱人 提交于 2019-12-05 11:17:56
问题 I have character varying entries in a table where some (not all) values contain percentages, e.g., '12%' , '97%' , etc. I want to find all the values that contain percentages. In other words, I want to find all values that end with a percent sign ( '%' ). 回答1: You can try like this: SELECT * FROM my_table WHERE my_column LIKE '%\%%' ESCAPE '\'; Format <like predicate> ::= <match value> [ NOT ] LIKE <pattern> [ ESCAPE <escape character> ] <match value> ::= <character value expression> <pattern

How should I escape characters inside this LIKE query?

前提是你 提交于 2019-12-05 11:05:58
I have a field in one of my tables that contains this string: !"#¤%&/()=?´`?=)(/&%¤#"!\'\'"' (Only for test purposes ofcourse). I've tried endless of queries to properly select this field, and without returning any errors of course, but I just can't seem to get it right. This is the query I'm using currently: SELECT * FROM mytable WHERE `column` LIKE '%!"#¤%&/()=?´`?=)(/&%¤#"!\\\'\\\'"\'%' Can anyone shed some light on what it is I'm not doing right? Are there any other characters (other than ' ) that I should escape? I haven't read about it anywhere... (I did however try adding backslashes

Emulate a SQL LIKE search with ElasticSearch

ε祈祈猫儿з 提交于 2019-12-05 10:29:11
I'm just beginning with ElasticSearch and trying to implement an autocomplete feature based on it. I have an autocomplete index with a field city of type string . Here's an example of a document stored into this index: { "_index":"autocomplete_1435797593949", "_type":"listing", "_id":"40716", "_source":{ "city":"Rome", "tags":[ "listings" ] } } The analyse configuration looks like this: { "analyzer":{ "autocomplete_term":{ "tokenizer":"autocomplete_edge", "filter":[ "lowercase" ] }, "autocomplete_search":{ "tokenizer":"keyword", "filter":[ "lowercase" ] } }, "tokenizer":{ "autocomplete_edge":{