Questions tagged [sql-like]

The LIKE predicate is used to search for a specific pattern in a column.

The LIKE predicate is used to search for a specified pattern in a column. The wildcard character % stands for a sequence of zero or more characters, the wildcard character _ stands for a single character.

Examples of usage:

Starts with P

SELECT * FROM Person
WHERE name LIKE 'P%'

Ends with P

WHERE name LIKE '%P'

Contains P (will match anywhere in the string so this potentially returns a lot of rows)

WHERE name LIKE '%P%'

Has an E as second character:

WHERE name LIKE '_E%'

You can also combine any other conditions using AND or OR operators.

References

3176 questions
10
votes
1 answer

How are strings passed to SQLAlchemy's .like() method

I'm building an interface on Flask using SQLAlchemy and part of it is a search API. Essentially a type-ahead input is calling the server with its value (for example an email) and then the server is performing a SQLalchemy query using .like in a…
jduren
  • 630
  • 5
  • 11
10
votes
1 answer

Possible bug in VB.NET 'Like' operator?

Why is it that the following evaluates as True? Dim result = "b" Like "*a*b" Thanks. EDIT: To generalize this a bit, the following returns True: "String1" Like "*AnyText1*AnyText2*AnyText???******????*String1" VBA works correctly, returning…
mcu
  • 3,302
  • 8
  • 38
  • 64
9
votes
5 answers

How should I escape characters inside this LIKE query?

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…
Nisto
  • 91
  • 1
  • 1
  • 2
9
votes
4 answers

Using "like" in a cursor/query with a parameter in python (django)

I know this may be something stupid but I decided to ask any way. I've been trying to query something like: cursor.execute("select col1, col2 \ from my_tablem \ where afield like '%%s%' …
Juan129
  • 101
  • 1
  • 1
  • 4
9
votes
2 answers

Elasticsearch equal SQL %Like%

Coming from here i'm asking myselve for the elasticsearch syntax for such querys: WHERE text LIKE "%quick%" AND text LIKE "%brown%" AND text LIKE "%fox%" my try (unfortunately without success) "query": { "bool": { "filter": [ …
Toshi
  • 2,532
  • 4
  • 17
  • 45
9
votes
4 answers

What code would I use to convert a SQL like expression to a regex on the fly?

I'm looking to convert a SQL like statement on the fly to the equivalent regex i.e. LIKE '%this%' LIKE 'Sm_th' LIKE '[C-P]arsen' What's the best approach to doing this? P.S. I'm looking to do this on the .Net Framework (C#).
Bittercoder
  • 11,753
  • 10
  • 58
  • 76
9
votes
3 answers

Dynamic Like Statement in SQL

I've been racking my brain on how to do this for a while, and i know that some genius on this site will have the answer. Basically i'm trying to do this: SELECT column FROM table WHERE [table].[column] LIKE string1 OR [table].[column]…
Derwent
  • 606
  • 1
  • 5
  • 13
9
votes
2 answers

Optimal Postgres text index for LIKE query?

Using Postgres 9.5, I have a table addresses. CREATE TABLE addresses ( id integer PRIMARY KEY, address text ); In that table I have 7.5 million rows. Example: 1, "1600 Pennsylvania Avenue NW, Washington, DC, 20500" I'm using this…
Tyler
  • 161
  • 1
  • 11
9
votes
4 answers

Perform a Case insensitive Like query in a case sensitive SQL Server database

This is my scenario. SQL Server 2014 Standard edition, I have a database with a collation SQL_Latin1_General_CP437_BIN2 which is case sensitive. I want to perform a LIKE query which should return the output irrespective of case sensitive. Ex: if i…
9
votes
6 answers

Sql Like to RegEx

Is there a good way to convert Regular Expression into LIKE inside a Function (MSSQL)? The sproc does not get more complicated than this: (country\=)(?[\w\d]+)(\&sessionid\=)(?.+) The groups will not be used in the LIKE, they…
Andreas
  • 1,311
  • 5
  • 24
  • 39
9
votes
2 answers

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

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…
abeger
  • 6,766
  • 7
  • 41
  • 58
9
votes
1 answer

Using a single array to pass multiple WHERE conditions (with LIKE)

Theory It's been discussed that one can use the following code to pass multiple WHERE clauses to single where() method in Laravel's Eloquent: $condition = array('field_1' => 'value_1', 'field_2' => 'value_2'); $users =…
lesssugar
  • 15,486
  • 18
  • 65
  • 115
9
votes
1 answer

How can LIKE '%...' seek on an index?

I would expect these two SELECTs to have the same execution plan and performance. Since there is a leading wildcard on the LIKE, I expect an index scan. When I run this and look at the plans, the first SELECT behaves as expected (with a scan). But…
9
votes
5 answers

Oracle query using 'like' on indexed number column, poor performance

On Query 1 a full table scan is being performed even though the id is an indexed column. Query 2 achieves the same result but much faster. If Query 1 is run returning an indexed column then it returns quickly but if non-indexed columns are returned…
James Collins
  • 309
  • 1
  • 2
  • 10
9
votes
6 answers

MYSQL WHERE LIKE Statement

I am attempting to use the LIKE clause in a mysql statement as follows: SELECT * FROM batches WHERE FilePath LIKE '%Parker_Apple_Ben_20-10-1956%' The data matched data within the 'FilePath' Column is: C:\SCAN\Parker_Apple_Ben_20-10-1830\TEST The…
Mike
  • 2,266
  • 10
  • 29
  • 37