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
18
votes
3 answers

SQLite query, 'LIKE'

I am trying to retrieve information from my database. I have words like Lim Won Mong and Limited. If I do my query, SELECT name FROM memberdb WHERE name LIKE '%LIM%', it displays both Lim Won Mong and Limited and I only want data from Lim Won…
Lene
  • 519
  • 2
  • 4
  • 17
17
votes
2 answers

How to ignore characters on a MYSQL SELECT LIKE %...%

I have a table with a phone column, where data may have spaces, dots,dashes or + signs between the numbers. I need to do a search with LIKE wildcards that ignore all those characters, for example: a record may have phone as "+123-456 78.90" a query…
Henry
  • 1,374
  • 2
  • 14
  • 24
17
votes
2 answers

How to SELECT using both wildcards (LIKE) and array (IN)?

In SQL, if you want to perform a SELECT with a wildcard, you'd use: SELECT * FROM table_name WHERE field_name LIKE '%value%' If you wanted to use an array of possible values, you'd use: SELECT * FROM table_name WHERE field_name IN ('one', 'two',…
Dave
  • 1,696
  • 4
  • 23
  • 47
17
votes
2 answers

Is it possible to perform a "LIKE" statement in a SSIS Expression?

I'm using a Derived Column Task to change column data using a CASE WHEN statement. However, I need to be able to say.. SQL CODE WOULD BE: CASE WHEN Column01 LIKE '%i%' THEN '0' ELSE '1' END In SSIS Expression Language that would be: [Column01] ==…
iamtheratio
  • 569
  • 4
  • 9
  • 16
17
votes
5 answers

T-SQL speed comparison between LEFT() vs. LIKE operator

I'm creating result paging based on first letter of certain nvarchar column and not the usual one, that usually pages on number of results. And I'm not faced with a challenge whether to filter results using LIKE operator or equality (=)…
Robert Koritnik
  • 103,639
  • 52
  • 277
  • 404
17
votes
3 answers

MySQL LIKE operator Vs MATCH AGAINST

Hi I'm worried about how to implement a simple search query, my scenario is: tag VARCHAR 255 Now I need to search inside the tag field and I can use two kinds of queries: SELECT * FROM table WHERE tag LIKE '%1111%' OR LIKE '%2222%' OR LIKE…
itsme
  • 48,972
  • 96
  • 224
  • 345
17
votes
2 answers

Selecting strings with LIKE operator in SPARQL

In ANSI SQL, you can write something like: SELECT * FROM DBTable WHERE Description LIKE 'MEET' or also: SELECT * FROM DBTable WHERE Description LIKE '%MEET%' What I would like help with is writing the SPARQL equivalent of the above please.
Kobojunkie
  • 6,375
  • 31
  • 109
  • 164
16
votes
4 answers

SQL select string that doesn't contain Y but contains X

I'm attempting to select all of the instances where this database field has a string but does not contain a specific value. Example: I'm trying to select every instance of "red chair" where "red chair" is not proceeded by "big". If I were to run…
Katzumi
  • 351
  • 2
  • 5
  • 16
16
votes
3 answers

How to do a LIKE in Entity Framework CORE (not full .net)

In the Full .Net EF LIKE's used to be SqlMethods.Like, eg: from c in dc.Organization where SqlMethods.Like(c.Boss, "%Jeremy%") This doesn't work in EF Core and I get this error: The name SqlMethods does not exist in the current context. So how do…
Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
16
votes
2 answers

How to use 'LIKE' statement with unicode strings?

I am trying to execute a query with unicode characters. I was able to execute the normal equality query by prepending N to the query (Eg: ..... WHERE column=N'exact_stringâ'). But that doesn't seem to work when I try to use LIKE. Any ideas on how to…
rkg
  • 5,559
  • 8
  • 37
  • 50
16
votes
4 answers

Find rows where text array contains value similar to input

I'm trying to get rows where a column of type text[] contains a value similar to some user input. What I've thought and done so far is to use the 'ANY' and 'LIKE' operator like this: select * from someTable where '%someInput%' LIKE…
Jose Hermosilla Rodrigo
  • 3,513
  • 6
  • 22
  • 38
16
votes
4 answers

How to query lucene with "like" operator?

The wildcard * can only be used at the end of a word, like user*. I want to query with a like %user%, how to do that?
Freewind
  • 193,756
  • 157
  • 432
  • 708
16
votes
2 answers

mysql datetime field with index get a range 'like' vs. 'between and' performance

I just find mysql can query datetime using like: like '2013-06-12%' I think it can not use the index. I Google it, but can not find such subject directly. So I have a test using a table with 3308614 records. The first SQL: SELECT * FROM…
bluearrow
  • 856
  • 2
  • 11
  • 26
15
votes
5 answers

What is the best way to search the Long datatype within an Oracle database?

I am working with an Oracle database that stores HTML as a Long datatype. I would like to query the database to search for a specific string within the HTML data stored in the Long. I tried, "select * from TABLE where COLUMN like '%form%'". This…
Mike Munroe
15
votes
4 answers

Avoiding SQL Injection in SQL query with Like Operator using parameters?

Taking over some code from my predecessor and I found a query that uses the Like operator: SELECT * FROM suppliers WHERE supplier_name like '%'+name+%'; Trying to avoid SQL Injection problem and parameterize this but I am not quite sure how this…
MikeJ
  • 14,430
  • 21
  • 71
  • 87