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
11
votes
11 answers

SQL LIKE Performance with only the wildcard (%) as a value

I am wondering what the performance of a query would be like using the LIKE keyword and the wildcard as the value compared to having no where clause at all. Consider a where clause such as "WHERE a LIKE '%'". This will match all possible values of…
Chris Dail
  • 25,715
  • 9
  • 65
  • 74
11
votes
5 answers

How to use LIKE in hibernate detached criteria for integer data type?

I have to do Restrictions.like("sequenceNo", "%" + Integer.valueOf(sequenceNo.trim()) + "%"). The field sequenceNo is integer type but the sequenceNo param value is string. My problem is I get an exception java.lang.ClassCastException:…
kwan_ah
  • 1,061
  • 1
  • 12
  • 18
11
votes
3 answers

How to improve sqlite like statement performance

I create a table use such schema: CREATE TABLE wordIndex(id integer primary key, word varchar(128), offset integer, length integer); CREATE INDEX word_idx on wordIndex(word); Now the table have about 450,000 row records.When I use Like statement…
ericfang
  • 343
  • 2
  • 8
10
votes
4 answers

Can we use "NOT LIKE " in sql

Can we use "NOT LIKE '%abc%'" just opposite of LIKE '%abc%' ? i tried and got some result but dont look like correct!! Is there anything similar to regex in SQL. Eg: i hae a table with 3 field. id name address 1 xyz 1234 abcd 2 abc …
zod
  • 12,092
  • 24
  • 70
  • 106
10
votes
8 answers

Combine PHP prepared statments with LIKE

Anyone know how to combine PHP prepared statements with LIKE? i.e. "SELECT * FROM table WHERE name LIKE %?%";
user29772
  • 1,457
  • 7
  • 21
  • 25
10
votes
1 answer

Pyspark: Filter data frame if column contains string from another column (SQL LIKE statement)

I am trying to filter my pyspark data frame the following way: I have one column which contains long_text and one column which contains numbers. If the long text contains the number I want to keep the column. I am trying to use the SQL LIKE…
LN_P
  • 1,448
  • 4
  • 21
  • 37
10
votes
5 answers

SQL: Is it possible to 'group by' according to 'like' function's results?

I am using Oracle SQL and I want to group some different rows that 'like' function results. To elaborate with an example: Let's assume I have a table MESA with one of the columns is a huge string. And I am counting the number of rows matching…
someone
  • 381
  • 3
  • 5
  • 14
10
votes
2 answers

Hive - LIKE Operator

I can not figure out how I deal with that problem: This is my Data: Table1: Table2: BRAND PRODUCT SOLD Sony Sony ABCD 1233 Apple Sony adv 1233 Google Sony aaaa …
Daniel
  • 552
  • 2
  • 9
  • 29
10
votes
1 answer

MYSQL: SELECT Method - but don't show duplicates / GROUP or DISTINCT?

How can I select and don't show duplicates? Actually, it's showing like that: apple | apple | apples | apple This is my code: $search = $_GET['q']; $query = "SELECT * FROM query WHERE searchquery LIKE '%$search%' AND searchquery <> '$search'";
elmaso
  • 193
  • 1
  • 2
  • 14
10
votes
4 answers

LIKE case-insensitive for not English letters

I want to retrieve rows whose TITLE field meets some pattern (case-insensitive), and this field contains only non-English letters. I tried this: SEARCH * FROM TABLE_NAME WHERE UPPER(column_name) LIKE UPPER('%pattern%'); However, this doesn't work,…
Leonid Semyonov
  • 473
  • 2
  • 6
  • 18
10
votes
4 answers

regex in SQL to detect one or more digit

I have the following query: SELECT * FROM `shop` WHERE `name` LIKE '%[0-9]+ store%' I wanted to match strings that says '129387 store', but the above regex doesn't work. Why is that?
adit
  • 32,574
  • 72
  • 229
  • 373
10
votes
3 answers

Multiple LIKE in sqlite

I'm trying to create a search function. If the search input field is "foo bar", I split it into two keywords then do this query: SELECT p.* FROM p_extra_fields as x INNER JOIN products as p ON x.product = p.id WHERE x.type = "1" AND ( …
Anna K.
  • 1,887
  • 6
  • 26
  • 38
10
votes
4 answers

Using JOIN statement with CONTAINS function

In SQL Server database I have a View with a lot of INNER JOINs statements. The last join uses LIKE predicate and that's why it's working too slowly. The query looks like : SELECT * FROM A INNER JOIN B ON A.ID = B.ID INNER JOIN C ON C.ID1 = B.ID1…
Alexander
  • 169
  • 1
  • 1
  • 9
10
votes
7 answers

How can I optimize/refactor a TSQL "LIKE" clause?

I have a table with 117000 or so records. I need to perform a search that checks 3 separate fields for a given string pattern. My where clause is as follows: field1 LIKE '%' + @DESC + '%' OR field2 LIKE '%' + @DESC + '%' OR field3 LIKE '%' + @DESC +…
IronicMuffin
  • 4,182
  • 12
  • 47
  • 90
10
votes
4 answers

Powershell - LIKE against an array

For every file being processed, its name is being checked to satisfy the condition. For example, given the following list of filters: $excludeFiles = @" aaa.bbb ccccc.* ddddd???.exe "@ | SplitAndTrim; It should exclude a file from processing if it…
Victor Zakharov
  • 25,801
  • 18
  • 85
  • 151