sql-like

Mysql: Order by like?

♀尐吖头ヾ 提交于 2019-12-17 06:29:34
问题 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")

MySQL SELECT LIKE or REGEXP to match multiple words in one record

情到浓时终转凉″ 提交于 2019-12-17 03:34:20
问题 The field table . name contains 'Stylus Photo 2100' and with the following query SELECT `name` FROM `table` WHERE `name` LIKE '%Stylus 2100%' I get no results. Of course i would if i searched SELECT `name` FROM `table` WHERE `name` LIKE '%Photo 2100%' How can I select the record by searching 'Stylus 2100' ? Thanks 回答1: Well if you know the order of your words.. you can use: SELECT `name` FROM `table` WHERE `name` REGEXP 'Stylus.+2100' Also you can use: SELECT `name` FROM `table` WHERE `name`

Escape a string in SQL Server so that it is safe to use in LIKE expression

限于喜欢 提交于 2019-12-17 02:10:21
问题 How do I escape a string in SQL Server's stored procedure so that it is safe to use in LIKE expression. Suppose I have an NVARCHAR variable like so: declare @myString NVARCHAR(100); And I want to use it in a LIKE expression: ... WHERE ... LIKE '%' + @myString + '%'; How do I escape the string (more specifically, characters that are meaningful to LIKE pattern matching, e.g. % or ? ) in T-SQL, so that it is safe to use in this manner? For example, given: @myString = 'aa%bb' I want: WHERE ...

VBScript - Return a Recordset in an Array (SQL Like function)

£可爱£侵袭症+ 提交于 2019-12-14 04:19:56
问题 I have to write a program for my company's accountant, and I have a problem in returning articles' families in an array, all of the families I want to have have an Accounting code who begins with "707". Here's my code in VBScript : Set objConnection = CreateObject("ADODB.Connection") Set rs = CreateObject("ADODB.Recordset") objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\BASES\Base.mdb;Persist Security Info=False" rs.CursorLocation = adUseClient FamilleQuery = "Select Code

Mysqli parameter binding issue

混江龙づ霸主 提交于 2019-12-14 01:04:31
问题 I need an extra set of eyes on this one. Any help will be greatly appreciated. This is a very simple search query, but for whatever reason I cannot find the bug. Well, I know where the bug is. I just can't get past it. Anyway..... I am taking a search value from a POST variable, setting that variable and then setting a column variable as follows... $term = "'%".$_POST['searchTerm']."%'"; $field = "columnName"; When I echo these they come up perfectly. So if I type "a" in the form I would be

Why is my LIKE query not returning any records in Microsoft Access 2013 only?

末鹿安然 提交于 2019-12-13 17:44:09
问题 My SQL query is as follows: SELECT * FROM Suppliers WHERE SupplierName LIKE 's%'; When I submit this query on W3 School's TryIt Editor (v1.2) (http://www.w3schools.com/sql/trysql.asp?filename=trysql_select_like), it returns a number of records where the SupplierName begins with the letter 'S', as expected. However, when I run this query on my own database in Access 2013, it doesn't return any records, even though my table name and field name are identical to W3's sample. Queries not using

Delete rows matching substring with LIKE?

我是研究僧i 提交于 2019-12-13 16:34:57
问题 How do you delete rows from a table, where a column contains a substring, but the type of that column is 'Long'. (Yes, I know I shouldn't use Long, but I'm maintaining someone else's mess). My first attempt was: delete from longtable where search_long(rowid) like '%hello%'; (Following on from this answer.) This returns: SQL Error: ORA-04091: table blah.longtable is mutating, trigger/function may not see it 回答1: I just replicated your problem and got the same error - it seems the function can

Does SQL Server optimize LIKE ('%%') query?

那年仲夏 提交于 2019-12-13 13:26:46
问题 I have a Stored Proc which performs search on records. The problem is that some of the search criteria,which are coming from UI, may be empty string. So, when the criteria not specified, the LIKE statement becomes redundant. How can I effectively perform that search or Sql Server? Or, Does it optimize LIKE('%%') query since it means there is nothing to compare? The Stored proc is like this: ALTER PROC [FRA].[MCC_SEARCH] @MCC_Code varchar(4), @MCC_Desc nvarchar(50), @Detail nvarchar(50) AS

Is there a way to combine IN and LIKE in MySQL?

江枫思渺然 提交于 2019-12-13 13:15:21
问题 I'm currently running a query like this: SELECT * FROM email WHERE email_address LIKE 'ajones@%' OR email_address LIKE 'bsmith@%' OR email_address LIKE 'cjohnson@%' The large number of OR 's bothers me. Is there a way to condense this up with something akin to an IN operator, e.g.: SELECT * FROM email WHERE email_address LIKE ('ajones@%', 'bsmith@%', 'cjohnson@%') Or is this just wishful thinking? 回答1: Here's what I recommend: Extract the part of the email address before the @ and use that

Optimising LIKE expressions that start with wildcards

北慕城南 提交于 2019-12-13 12:55:35
问题 I have a table in a SQL Server database with an address field (ex. 1 Farnham Road, Guildford, Surrey, GU2XFF) which I want to search with a wildcard before and after the search string. SELECT * FROM Table WHERE Address_Field LIKE '%nham%' I have around 2 million records in this table and I'm finding that queries take anywhere from 5-10s, which isn't ideal. I believe this is because of the preceding wildcard. I think I'm right in saying that any indexes won't be used for seek operations