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
121
votes
2 answers

How can I use 'Not Like' operator in MongoDB

I can use the SQL Like Operator using pymongo, db.test.find({'c':{'$regex':'ttt'}}) But how can I use Not Like Operator? I tried db.test.find({'c':{'$not':{'$regex':'ttt'}}) but got error: OperationFailure: $not cannot have a regex
KyungHoon Kim
  • 2,859
  • 2
  • 23
  • 26
112
votes
13 answers

SQL Server datetime LIKE select?

in MySQL select * from record where register_date like '2009-10-10%' What is the syntax in SQL Server?
Paisal
  • 1,311
  • 3
  • 11
  • 13
107
votes
16 answers

LIKE operator in LINQ

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…
shamim
  • 6,640
  • 20
  • 85
  • 151
105
votes
9 answers

Parameter in like clause JPQL

I am trying to write a JPQL query with a like clause: LIKE '%:code%' I would like to have code=4 and find 455 554 646 ... I cannot pass :code = '%value%' namedQuery.setParameter("%" + this.value + "%"); because in another place I need :value not…
Manuele Piastra
104
votes
2 answers

How do you force mysql LIKE to be case sensitive?

Possible Duplicate: Mysql Like Case Sensitive Mysql ignores case for its LIKE comparisons. How can you force it to perform case-sensitive LIKE comparisons?
Bohemian
  • 412,405
  • 93
  • 575
  • 722
97
votes
5 answers

Use of SqlParameter in SQL LIKE clause not working

I have the following code: const string Sql = @"select distinct [name] from tblCustomers left outer join tblCustomerInfo on tblCustomers.Id = tblCustomerInfo.CustomerId where (tblCustomer.Name LIKE '%@SEARCH%' OR…
coder_bro
  • 10,503
  • 13
  • 56
  • 88
97
votes
5 answers

Using Eloquent ORM in Laravel to perform search of database using LIKE

I want to use Eloquent's active record building to build a search query, but it is going to be a LIKE search. I have found the User::find($term) or User::find(1), but this is not generating a like statement. I'm not looking for a direct answer, but…
Jonathan
  • 1,135
  • 1
  • 10
  • 15
87
votes
6 answers

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

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 '%'…
Artur
83
votes
2 answers

Use LIKE %..% with field values in MySQL

I stumbled into a delicate SQL problem when I needed to use a value from a field inside a LIKE %..% statement. Example: SELECT t1.Notes, t2.Name FROM Table1 t1, Table2 t2 WHERE t1.Notes LIKE '%t2.Name%' This is only an example from the top of my…
Max Kielland
  • 5,627
  • 9
  • 60
  • 95
82
votes
7 answers

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

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…
Alessio Firenze
  • 1,013
  • 1
  • 8
  • 13
80
votes
9 answers

How to speed up SELECT .. LIKE queries in MySQL on multiple columns?

I have a MySQL table for which I do very frequent SELECT x, y, z FROM table WHERE x LIKE '%text%' OR y LIKE '%text%' OR z LIKE '%text%' queries. Would any kind of index help speed things up? There are a few million records in the table. If there is…
Tom
  • 6,991
  • 13
  • 60
  • 78
79
votes
7 answers

Search for string within text column in MySQL

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…
user94154
  • 16,176
  • 20
  • 77
  • 116
76
votes
3 answers

Element or class LIKE selector for jQuery?

For whatever reason I have these classes called .main_sub1, .main_sub2 etc. Never mind why I can't have .main .sub. Is there a way with jQuery, sort of in the way it is possible to do with attributes, to get the classes containing main?
David Andersson
  • 1,246
  • 2
  • 11
  • 17
74
votes
3 answers

How to escape underscore character in PATINDEX pattern argument?

I've found a solution for finding the position of an underscore with PATINDEX : DECLARE @a VARCHAR(10) SET @a = '37_21' PRINT PATINDEX('%_%', @a) -- return 1 (false) PRINT PATINDEX('%!%', REPLACE(@a, '_', '!')) -- return 3…
podosta
  • 1,922
  • 1
  • 17
  • 15
69
votes
10 answers

SQL query for a carriage return in a string and ultimately removing carriage return

SQL query for a carriage return in a string and ultimately removing carriage return I have some data in a table and there are some carriage returns in places where I don't want them. I am trying to write a query to get all of the strings that…
Maestro1024
  • 3,173
  • 8
  • 35
  • 52