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
33
votes
5 answers

SQL Server: use CASE with LIKE

I am pretty new to SQL and hope someone here can help me with this. I have a stored procedure where I would like to pass a different value depending on whether a column contains a certain country or not. So far I only used CASE when checking for…
Mike
  • 815
  • 7
  • 15
  • 23
32
votes
2 answers

SWITCH with LIKE inside SELECT query in MySQL

I have this Tags table CREATE TABLE IF NOT EXISTS `Tags` ( `id_tag` int(10) unsigned NOT NULL auto_increment, `tag` varchar(255) default NULL, PRIMARY KEY (`id_tag`), UNIQUE KEY `tag` (`tag`), KEY `id_tag` (`id_tag`), KEY `tag_2`…
Sandeepan Nath
  • 9,966
  • 17
  • 86
  • 144
31
votes
2 answers

Should LIKE 'searchstr%' use an index?

I have a database with several fields : word_id — INTEGER PRIMARY_KEY word — TEXT ... And ~150k rows. Since this is a dictionary, I'm searching for a word with mask 'search_string%' using LIKE. It used to work, taking 15ms to find matching rows.…
nikans
  • 2,468
  • 1
  • 28
  • 35
30
votes
9 answers

SQL LIKE % inside array

I know how to perform an SQL LIKE % query for a single value like so: SELECT * FROM users WHERE name LIKE %tom%; but how do I do this if the search terms for my LIKE comes from an array? For example, let's say we have an array like this: $words =…
user765368
  • 19,590
  • 27
  • 96
  • 167
30
votes
11 answers

Using LIKE in an Oracle IN clause

I know I can write a query that will return all rows that contain any number of values in a given column, like so: Select * from tbl where my_col in (val1, val2, val3,... valn) but if val1, for example, can appear anywhere in my_col, which has…
DeveloperM
  • 1,129
  • 7
  • 17
  • 30
30
votes
2 answers

doctrine2 dql, use setParameter with % wildcard when doing a like comparison

I want to use the parameter place holder - e.g. ?1 - with the % wild cards. that is, something like: "u.name LIKE %?1%" (though this throws an error). The docs have the following two examples: 1. // Example - $qb->expr()->like('u.firstname',…
waigani
  • 3,570
  • 5
  • 46
  • 71
29
votes
8 answers

Match only entire words with LIKE?

So 'awesome document' LIKE '%doc%' is true, because doc is a sub-string. But, I want it to be false while 'awesome doc' or 'doc awesome' or 'awesome doc awesome' should be true. How can I do with with a like? I'm using sqlite, so I hope I don't have…
Abhinav Sharma
  • 1,145
  • 4
  • 11
  • 12
29
votes
2 answers

HQL like operator for case insensitive search

I am implementing an autocomplete functionality using Jquery, when I type the name, it fetches the record from the db, The records stored in db are mixture of capital & small letters. I have written a HQL Query which fetches me the records with…
madhu
  • 1,010
  • 5
  • 20
  • 38
28
votes
8 answers

Python String Formats with SQL Wildcards and LIKE

I'm having a hard time getting some sql in python to correctly go through MySQLdb. It's pythons string formatting that is killing me. My sql statement is using the LIKE keyword with wildcards. I've tried a number of different things in Python. The…
gngrwzrd
  • 5,902
  • 4
  • 43
  • 56
27
votes
8 answers

Regular expression to match start of filename and filename extension

What is the regular expression to match strings (in this case, file names) that start with 'Run' and have a filename extension of '.py'? The regular expression should match any of the following: RunFoo.py RunBar.py Run42.py It should not…
Ray
  • 187,153
  • 97
  • 222
  • 204
26
votes
8 answers

Is there a Hive equivalent of SQL "not like"

While Hive supports positive like queries: ex. select * from table_name where column_name like 'root~%'; Hive Does not support negative like queries: ex. select * from table_name where column_name not like 'root~%'; Does anyone know an…
CMaury
  • 1,273
  • 5
  • 13
  • 25
26
votes
6 answers

Full text search vs LIKE

My question is about using full text search. As I know like queries which begin with % never use index : SELECT * from customer where name like %username% If I use fulltext for this query can I take better performance? Can SQL Server use fulltext…
profvm
  • 261
  • 1
  • 3
  • 3
26
votes
7 answers

Using LIKE operator with stored procedure parameters

I have a stored procedure that uses the LIKE operator to search for a truck location among some other parameters @location nchar(20), @time time, @date date AS select DonationsTruck.VechileId, Phone, Location, [Date], [Time] …
Scarnet
  • 738
  • 2
  • 11
  • 36
25
votes
5 answers

LIKE with integers, in SQL

Can I replace the = statement with the LIKE one for the integers ? by eg. are the following the same thing: select * from FOOS where FOOID like 2 // and select * from FOOS where FOOID = 2 I'd prefer to use LIKE instead of = because I could…
serhio
  • 28,010
  • 62
  • 221
  • 374
25
votes
2 answers

how to make a like search in postgresql and node js

I am using node js and the module pg for connect to postrgresql i want to make a search for a database of tags but i can't make it work, in the variable tag i saved the param of the url , but the consult doesn't return any results. how can i…
Jose Sosa
  • 2,157
  • 3
  • 17
  • 18