sql-like

Like Case Sensitive in MySQL

你。 提交于 2019-11-27 01:33:07
I have a MySQL query: SELECT concat_ws(title,description) as concatenated HAVING concatenated LIKE '%SearchTerm%'; And my table is encoded utf8_general_ci with MyISAM. Searches seem to be case sensitive. I can't figure out how to fix it. What's going wrong and/or how do I fix it? Try this: SELECT LOWER(CONCAT_WS(title,description)) AS concatenated WHERE concatenated LIKE '%searchterm%' or (to let you see the difference) SELECT LOWER(CONCAT_WS(title,description)) AS concatenated WHERE concatenated LIKE LOWER('%SearchTerm%') A much better solution in terms of performance: SELECT .... FROM ....

MySQL join query using like?

拥有回忆 提交于 2019-11-27 01:31:11
I have been trying to get this working for quite a while now but it just doesn't seem to work, maybe it is is not even possible, what i am wanting to do is to perform a MySQL join query using like, such as this example i found... SELECT * FROM Table1 INNER JOIN Table2 ON Table1.col LIKE '%' + Table2.col + '%' but it just doesn't seem to work at all, any help that can be given would be brilliant, thanks ! Try SELECT * FROM Table1 INNER JOIN Table2 ON Table1.col LIKE CONCAT('%', Table2.col, '%') MySQL does string concatenation differently from other databases, so in case you want to port your

Regular expression to match start of filename and filename extension

心已入冬 提交于 2019-11-27 01:07:42
问题 What is the regular expression to match strings (in this case, file names) that start with 'Run' and have a filename extension of '.py'? The regular expression should match any of the following: RunFoo.py RunBar.py Run42.py It should not match: myRunFoo.py RunBar.py1 Run42.txt The SQL equivalent of what I am looking for is ... LIKE 'Run%.py' ... . 回答1: For a regular expression, you would use: re.match(r'Run.*\.py$') A quick explanation: . means match any character. * means match any

Mysql: Order by like?

倾然丶 夕夏残阳落幕 提交于 2019-11-27 00:27:57
assume that we are performing search using keywords: keyword1, keyword2, keyword3 there are records in database with column "name": 1: John Doe 2: Samuel Doe 3: John Smith 4: Anna Smith now Query: SELECT * FROM users WHERE (name LIKE "%John%" OR name LIKE "%Doe%") it will select records: 1,2,3 (in this order) but i want to order it by keyword in example keyword1=John, keyword2=Doe so it should be listed by keywords: 1,3,2 (because i want to perform search for "Doe" after searching for "John") I was thinking about SELECT DISTINCT FROM (...... UNION .....) but it will be much easier to order it

LIKE vs CONTAINS on SQL Server

纵饮孤独 提交于 2019-11-26 21:18:20
Which one of the following queries is faster (LIKE vs CONTAINS)? SELECT * FROM table WHERE Column LIKE '%test%'; or SELECT * FROM table WHERE Contains(Column, "test"); The second (assuming you means CONTAINS , and actually put it in a valid query) should be faster, because it can use some form of index (in this case, a full text index). Of course, this form of query is only available if the column is in a full text index. If it isn't, then only the first form is available. The first query, using LIKE, will be unable to use an index, since it starts with a wildcard, so will always require a

how to safely generate a SQL LIKE statement using python db-api

不问归期 提交于 2019-11-26 21:13:59
问题 I am trying to assemble the following SQL statement using python's db-api: SELECT x FROM myTable WHERE x LIKE 'BEGINNING_OF_STRING%'; where BEGINNING_OF_STRING should be a python var to be safely filled in through the DB-API. I tried beginningOfString = 'abc' cursor.execute('SELECT x FROM myTable WHERE x LIKE '%s%', beginningOfString) cursor.execute('SELECT x FROM myTable WHERE x LIKE '%s%%', beginningOfString) I am out of ideas; what is the correct way to do this? 回答1: It's best to separate

Python SQLite parameter substitution with wildcards in LIKE

随声附和 提交于 2019-11-26 20:34:29
I am attempting to use a parametrized LIKE query with Python's Sqlite library as below: self.cursor.execute("select string from stringtable where string like '%?%' and type = ?", (searchstr,type)) but the ? inside of the wildcard is not being evaluated leaving me with this error: "sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 2 supplied." I also tried to use the tagged version of querying with: like '%:searchstr%' and in the list having {"searchstr":searchstr... but when I do that the query runs but never returns any results even

LIKE operator in LINQ

橙三吉。 提交于 2019-11-26 20:28:14
Is there any way to compare strings in a C# LINQ expression similar to SQL's LIKE operator? Suppose I have a string list. On this list I want to search a string. In SQL, I could write: SELECT * FROM DischargePort WHERE PortName LIKE '%BALTIMORE%' Instead of the above, query want a linq syntax. using System.Text.RegularExpressions; … var regex = new Regex(sDischargePort, RegexOptions.IgnoreCase); var sPortCode = Database.DischargePorts .Where(p => regex.IsMatch(p.PortName)) .Single().PortCode; My above LINQ syntax does not work. What have I got wrong? Typically you use String.StartsWith /

Using OR in LIKE Query in MySQL to compare multiple fields

本小妞迷上赌 提交于 2019-11-26 20:24:36
问题 I always thought that you could use OR in a LIKE statment to query things in MySQL. So, if I wanted to compare multiple fields in a row to 1 keyword or term: SELECT * FROM MyTable WHERE Column1 OR Column2 LIKE '%keyword%'; and if I had an array of words to compare: SELECT * FROM MyTable WHERE Column1 OR Column2 LIKE '%keyword1%' AND Column1 OR Column2 LIKE '%keyword2%'; I don't believe that syntax is correct, however. Is there an efficient method of writing this aside from something like:

Search for string within text column in MySQL

半城伤御伤魂 提交于 2019-11-26 20:18:54
I have mysql table that has a column that stores xml as a string. I need to find all tuples where the xml column contains a given string of 6 characters. Nothing else matters--all I need to know is if this 6 character string is there or not. So it probably doesn't matter that the text is formatted as xml. Question: how can I search within mysql? ie SELECT * FROM items WHERE items.xml [contains the text '123456'] Is there a way I can use the LIKE operator to do this? You could probably use the LIKE clause to do some simple string matching: SELECT * FROM items WHERE items.xml LIKE '%123456%' If