sql-like

MySQL - JOIN with table on partial string match

大憨熊 提交于 2020-04-18 05:47:45
问题 Trying to LEFT JOIN a table with partial string match. I've tried changing the wildcard in the LIKE condition, but it still only searches for the full string. Any suggestions? I've got a list of product abbreviations stored in a table. Would be easier to manage this list with partial matching versus having to spell out every product. Thanks in advance! CREATE TABLE `order` ( order_id INT (11) NOT NULL, shipping_firstname VARCHAR (128) NOT NULL, shipping_lastname VARCHAR (128) NOT NULL );

PDO prepare with question marks doesn't work with numbers [duplicate]

时光怂恿深爱的人放手 提交于 2020-04-11 17:11:33
问题 This question already has answers here : Reference — frequently asked questions about PDO (3 answers) Closed 6 years ago . I have this : $pdo = new PDO('mysql:host=localhost;dbname=mydb', 'user', 'pass'); $max = 10; $min = 0; $q = $_GET['q']; $result = $pdo->prepare("SELECT * FROM fruits WHERE name LIKE ? LIMIT ?, ?"); $result->execute(array('%'.$q.'%', $min, $max)); However it doesn't work (returns nothing) while when I replace LIMIT by LIMIT 0, 10 and remove $min and $max from the array it

PDO prepare with question marks doesn't work with numbers [duplicate]

ⅰ亾dé卋堺 提交于 2020-04-11 17:11:09
问题 This question already has answers here : Reference — frequently asked questions about PDO (3 answers) Closed 6 years ago . I have this : $pdo = new PDO('mysql:host=localhost;dbname=mydb', 'user', 'pass'); $max = 10; $min = 0; $q = $_GET['q']; $result = $pdo->prepare("SELECT * FROM fruits WHERE name LIKE ? LIMIT ?, ?"); $result->execute(array('%'.$q.'%', $min, $max)); However it doesn't work (returns nothing) while when I replace LIMIT by LIMIT 0, 10 and remove $min and $max from the array it

PDO prepare with question marks doesn't work with numbers [duplicate]

ぃ、小莉子 提交于 2020-04-11 17:11:05
问题 This question already has answers here : Reference — frequently asked questions about PDO (3 answers) Closed 6 years ago . I have this : $pdo = new PDO('mysql:host=localhost;dbname=mydb', 'user', 'pass'); $max = 10; $min = 0; $q = $_GET['q']; $result = $pdo->prepare("SELECT * FROM fruits WHERE name LIKE ? LIMIT ?, ?"); $result->execute(array('%'.$q.'%', $min, $max)); However it doesn't work (returns nothing) while when I replace LIMIT by LIMIT 0, 10 and remove $min and $max from the array it

Select rows based on textarea value

痴心易碎 提交于 2020-03-06 09:21:06
问题 Depending on the search pattern I need to get the data displayed from the server. include("dbconfig.php"); $sql="select * from blog where title LIKE '{$title}%'"; $res=mysql_query($sql); while($row=mysql_fetch_array($res)) { echo"<tr>"; echo"<td><img src='uploads/".$row['file']."' height='150px' width='200px'</td>"; echo"<td><h3>".$row['title']."</h3>".$row['description']."</td>"; echo"</tr>"; } 回答1: Here is a complete rewrite that implements mysqli as commented under the question. For

mysql datetime field with index get a range 'like' vs. 'between and' performance

谁说我不能喝 提交于 2020-02-20 07:12:11
问题 I just find mysql can query datetime using like: like '2013-06-12%' I think it can not use the index. I Google it, but can not find such subject directly. So I have a test using a table with 3308614 records. The first SQL: SELECT * FROM subscription t WHERE DATE(t.active_time) = '2013-06-30'; All we know this SQL can not use the index and it takes 4 seconds to get the result. The second SQL: SELECT * FROM subscription t WHERE t.active_time LIKE '2013-06-30%'; I don't know if it can use the

MySQL SELECT values with more than three words

元气小坏坏 提交于 2020-01-25 11:39:25
问题 I currently have the following code select * FROM list WHERE name LIKE '___' ORDER BY name; I am trying to get it so that it only shows names with three or more words. It only displays names with three characters I cannot seem to work out the correct syntax for this. Any help is appreciated Thankyou 回答1: If you assume that there are no double spaces, you can do: WHERE name like '% % %' To get names with three or more words. If you can have double spaces (or other punctuation), then you are

SQLite fuzzy duplicate search using LIKE

蹲街弑〆低调 提交于 2020-01-23 21:28:28
问题 I have a table with 4 entries. CREATE TABLE tab( name Text ); INSERT INTO "tab" VALUES('Intertek'); INSERT INTO "tab" VALUES('Pntertek'); INSERT INTO "tab" VALUES('Ontertek'); INSERT INTO "tab" VALUES('ZTPay'); Pntertek & Ontertek are fuzzy duplicates of the correctly spelt Intertek. I wish to create a list consisting of fuzzy duplicates and the correctly spelt names. However, I don't want the list to contain the correctly spelt name if there is no fuzzy duplicate found by the LIKE search.

PostgreSQL performance difference between LIKE and regex

人走茶凉 提交于 2020-01-22 19:46:48
问题 Could someone explain such a big performance difference between these SQLs ? SELECT count(*) as cnt FROM table WHERE name ~ '\*{3}'; -- Total runtime 12.000 - 18.000 ms SELECT count(*) as cnt FROM table WHERE name ~ '\*\*\*'; -- Total runtime 12.000 - 18.000 ms SELECT count(*) as cnt FROM table WHERE name LIKE '%***%'; -- Total runtime 5.000 - 7.000 ms As you can see, the difference is more than double between LIKE operator and simple regular expression (I thought LIKE operator internally

Convert date to string in Hibernate Criteria

别说谁变了你拦得住时间么 提交于 2020-01-21 12:14:49
问题 Is it possible to perform a request that checks the string representation of a Date instance. For example Restrictions.like("dateField", "%12%") to retrieve dates that either have String 12 in day or 12 in month or 12 in year where "dateField" is an instance of java.util.Date Thanks 回答1: I had the same problem and here's what I did: First, I created my own Criterion implementation: public class DateLikeExpression implements Criterion { private static final long serialVersionUID = 1L; private