Questions tagged [sql-like]
The LIKE predicate is used to search for a specific pattern in a column.
3,210
questions
1934
votes
47
answers
1.8m
views
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.
587
votes
16
answers
553k
views
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 ...
436
votes
16
answers
560k
views
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 ...
413
votes
15
answers
461k
views
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 ...
406
votes
5
answers
1.3m
views
Combining "LIKE" and "IN" for SQL Server [duplicate]
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:...
368
votes
16
answers
429k
views
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?
306
votes
10
answers
221k
views
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 ...
279
votes
5
answers
1.5m
views
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");
270
votes
7
answers
382k
views
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?
200
votes
9
answers
440k
views
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 ...
197
votes
9
answers
505k
views
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 ...
174
votes
5
answers
93k
views
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 ...
161
votes
8
answers
152k
views
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 ...
146
votes
5
answers
359k
views
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 ...
134
votes
8
answers
208k
views
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 ...
124
votes
2
answers
118k
views
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:
...
113
votes
13
answers
414k
views
SQL Server datetime LIKE select?
in MySQL
select * from record where register_date like '2009-10-10%'
What is the syntax in SQL Server?
112
votes
16
answers
329k
views
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 ...
110
votes
3
answers
191k
views
T-SQL and the WHERE LIKE %Parameter% clause
I was trying to write a statement which uses the WHERE LIKE '%text%' clause, but I am not receiving results when I try to use a parameter for the text. For example, this works:
SELECT Employee WHERE ...
108
votes
2
answers
73k
views
How do you force mysql LIKE to be case sensitive? [duplicate]
Possible Duplicate:
Mysql Like Case Sensitive
Mysql ignores case for its LIKE comparisons.
How can you force it to perform case-sensitive LIKE comparisons?
106
votes
10
answers
149k
views
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 +...
98
votes
5
answers
153k
views
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 ...
98
votes
6
answers
101k
views
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
...
88
votes
6
answers
220k
views
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 ...
84
votes
7
answers
216k
views
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 `...
84
votes
2
answers
183k
views
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....
81
votes
9
answers
94k
views
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 ...
81
votes
7
answers
299k
views
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 ...
76
votes
3
answers
100k
views
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,...
74
votes
3
answers
60k
views
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 ...
70
votes
10
answers
306k
views
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 ...
70
votes
5
answers
220k
views
how to use a like with a join in sql?
I have 2 tables, say table A and table B and I want to perform a join, but the matching condition has to be where a column from A 'is like' a column from B meaning that anything can come before or ...
68
votes
9
answers
120k
views
SQL SELECT LIKE (Insensitive casing)
I am trying to execute the sql query:
select * from table where column like '%value%';
But the data is saved as 'Value' ( V is capital ).
When I execute this query i don't get any rows.
How do i ...
66
votes
2
answers
302k
views
MySQL: NOT LIKE
I have these text in my db,
categories_posts
categories_news
posts_add
news_add
And I don't want to select the rows with categories, I use a query something like this,
SELECT *
FROM ...
61
votes
4
answers
104k
views
SQLite Like % and _
I can't figure out what the underscore character does in an SQLite like statement.
The wildcard character, %, is probably the same as in most other SQL databases.
So, what does the _ character do?
59
votes
2
answers
69k
views
How can I with mysqli make a query with LIKE and get all results?
This is my code but it dosn't work:
$param = "%{$_POST['user']}%";
$stmt = $db->prepare("SELECT id,Username FROM users WHERE Username LIKE ?");
$stmt->bind_param("s"...
58
votes
3
answers
63k
views
MySQL join query using like?
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, ...
56
votes
1
answer
105k
views
MySQL starts with searching issue
I'm having an issue using the % wildcard with a MySQL query.
http://www.w3schools.com/sql/sql_like.asp
Having read that article, I am using % and not getting quite what I was expecting.
I have a ...
54
votes
7
answers
144k
views
'LIKE ('%this%' OR '%that%') and something=else' not working
I have a select query where I am trying to search strings for multiple patterns
LIKE ('%this%' or '%that%' ) and something=else
Returns zero results
However
LIKE '%this%' and something=else
...
54
votes
4
answers
149k
views
SQL SELECT WHERE string ends with Column
I have this table in SQL Server 2012:
Id INT
DomainName NVARCHAR(150)
And the table have these DomainName values
google.com
microsoft.com
othersite.com
And this value:
mail.othersite.com
and I ...
54
votes
4
answers
8k
views
NOT LIKE and LIKE not returning opposite result
I have a table with 200 records out of which 10 records has text containing the word 'TAX'.
When I'm executing
Select * from tbl1 WHERE [TextCol] LIKE '%TAX%'
then I get the result set with those ...
54
votes
4
answers
29k
views
SQL LIKE with no wildcards the same as '='?
I know this is a pretty basic question, and I think I know the answer...but I'd like to confirm.
Are these queries truly equivalent?
SELECT * FROM FOO WHERE BAR LIKE 'X'
SELECT * FROM FOO WHERE BAR =...
53
votes
5
answers
107k
views
PostgreSQL: Select data with a like on timestamp field
I am trying to select data from a table, using a "like" on date field "date_checked" (timestamp). But I have this error :
SQLSTATE[42883]: Undefined function: 7 ERROR: operator does not exist: ...
53
votes
1
answer
43k
views
LIKE with % on column names
Here is my query that results in a syntax error:
SELECT *
FROM account_invoice,sale_order
WHERE sale_order.name LIKE %account_invoice.origin%
The account_invoice.origin field contains the text of ...
52
votes
2
answers
41k
views
Python SQLite parameter substitution with wildcards in LIKE
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))
...
50
votes
3
answers
199k
views
Create hive table using "as select" or "like" and also specify delimiter
Is it possible to do a
create table <mytable> as select <query statement>
using
row format delimited fields terminated by '|';
or to do a
create table <mytable> like <...
50
votes
3
answers
82k
views
Performance of like '%Query%' vs full text search CONTAINS query
I have a situation where I would like to search a single word.
For that scenario, which query would be good from a performance point of view?
Select Col1, Col2 from Table Where Col1 Like '%Search%'
...
46
votes
5
answers
58k
views
implement LIKE query in PDO
I am running problems in implementing LIKE in PDO
I have this query:
$query = "SELECT * FROM tbl WHERE address LIKE '%?%' OR address LIKE '%?%'";
$params = array($var1, $var2);
$stmt = $handle->...
46
votes
5
answers
219k
views
SQL Not Like Statement not working
I have the following code within a stored procedure.
WHERE
WPP.ACCEPTED = 1 AND
WPI.EMAIL LIKE '%@MATH.UCLA.EDU%' AND
(WPP.SPEAKER = 0 OR
WPP.SPEAKER IS NULL) AND
WPP.COMMENT NOT ...
44
votes
4
answers
47k
views
Which is faster — INSTR or LIKE?
If your goal is to test if a string exists in a MySQL column (of type 'varchar', 'text', 'blob', etc) which of the following is faster / more efficient / better to use, and why?
Or, is there some ...