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
1890
votes
46 answers

How to query MongoDB with "like"

I want to query something with SQL's like query: SELECT * FROM users WHERE name LIKE '%m%' How can I achieve the same in MongoDB? I can't find an operator for like in the documentation.
Freewind
  • 193,756
  • 157
  • 432
  • 708
563
votes
15 answers

How to make "case-insensitive" query in Postgresql?

Is there any way to write case-insensitive queries in PostgreSQL, E.g. I want that following 3 queries return same result. SELECT id FROM groups where name='administrator' SELECT id FROM groups where name='ADMINISTRATOR' SELECT id FROM groups…
Jame
  • 21,150
  • 37
  • 80
  • 107
420
votes
16 answers

How can I search (case-insensitive) in a column using LIKE wildcard?

I looked around some and didn't find what I was after so here goes. SELECT * FROM trees WHERE trees.`title` LIKE '%elm%' This works fine, but not if the tree is named Elm or ELM etc... How do I make SQL case insensitive for this wild-card…
David Morrow
  • 8,965
  • 4
  • 29
  • 24
411
votes
15 answers

How to do SQL Like % in Linq?

I have a procedure in SQL that I am trying to turn into Linq: SELECT O.Id, O.Name as Organization FROM Organizations O JOIN OrganizationsHierarchy OH ON O.Id=OH.OrganizationsId where OH.Hierarchy like '%/12/%' The line I am most concerned with…
Matt Dell
  • 9,205
  • 11
  • 41
  • 58
394
votes
5 answers

Combining "LIKE" and "IN" for SQL Server

Is it possible to combine LIKE and IN in a SQL Server-Query? So, that this query SELECT * FROM table WHERE column LIKE IN ('Text%', 'Link%', 'Hello%', '%World%') Finds any of these possible matches: Text, Textasd, Text hello, Link2, Linkomg,…
F.P
  • 17,421
  • 34
  • 123
  • 189
364
votes
16 answers

Equals(=) vs. LIKE

When using SQL, are there any benefits of using = in a WHERE clause instead of LIKE? Without any special operators, LIKE and = are the same, right?
Travis
  • 12,001
  • 8
  • 39
  • 52
297
votes
10 answers

How can I escape square brackets in a LIKE clause?

I am trying to filter items with a stored procedure using like. The column is a varchar(15). The items I am trying to filter have square brackets in the name. For example: WC[R]S123456. If I do a LIKE 'WC[R]S123456' it will not return anything. I…
Travis
  • 3,389
  • 2
  • 19
  • 11
275
votes
5 answers

LIKE vs CONTAINS on SQL Server

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");
user667429
  • 2,993
  • 2
  • 18
  • 15
264
votes
7 answers

Case insensitive searching in Oracle

The default behaviour of LIKE and the other comparison operators, = etc is case-sensitive. Is it possible make them case-insensitive?
sergionni
  • 13,290
  • 42
  • 132
  • 189
197
votes
9 answers

MySQL Like multiple values

I have this MySQL query. I have database fields with this contents sports,shopping,pool,pc,games shopping,pool,pc,games sports,pub,swimming, pool, pc, games Why does this like query does not work? I need the fields with either sports or pub or…
webmasters
  • 5,663
  • 14
  • 51
  • 78
192
votes
9 answers

SQL- Ignore case while searching for a string

I have the following data in a Table PriceOrderShipped PriceOrderShippedInbound PriceOrderShippedOutbound In SQL I need to write a query which searches for a string in a table. While searching for a string it should ignore case. For the below…
shockwave
  • 3,074
  • 9
  • 35
  • 60
172
votes
5 answers

What is Full Text Search vs LIKE

I just read a post mentioning "full text search" in SQL. I was just wondering what the difference between FTS and LIKE are. I did read a couple of articles but couldn't find anything that explained it well.
Nathan W
  • 54,475
  • 27
  • 99
  • 146
152
votes
8 answers

PostgreSQL LIKE query performance variations

I have been seeing quite a large variation in response times regarding LIKE queries to a particular table in my database. Sometimes I will get results within 200-400 ms (very acceptable) but other times it might take as much as 30 seconds to return…
Jason
  • 2,259
  • 2
  • 17
  • 12
136
votes
5 answers

List of special characters for SQL LIKE clause

What is the complete list of all special characters for a SQL (I'm interested in SQL Server but other's would be good too) LIKE clause? E.g. SELECT Name FROM Person WHERE Name LIKE '%Jon%' SQL Server: % _ [specifier] E.g. [a-z] [^specifier] ESCAPE…
Jonathan Parker
  • 6,705
  • 3
  • 43
  • 54
129
votes
8 answers

Is the LIKE operator case-sensitive with SQL Server?

In the documentation about the LIKE operator, nothing is told about the case-sensitivity of it. Is it? How to enable/disable it? I am querying varchar(n) columns, on an Microsoft SQL Server 2005 installation, if that matters.
Marcel
  • 15,039
  • 20
  • 92
  • 150
1
2 3
99 100