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
1
vote
2 answers

Avoiding using LIKE in SQLQueries

What can I use instead of LIKE in the queries? As LIKE has poor performance impact on the search condition. My scenario: SELECT * FROM MetaDataTag WHERE Name LIKE 'SUN RCC%' I cant use contains as a Full text index is required on the…
SESHI
  • 33
  • 2
  • 7
1
vote
2 answers

Using UNION instead of OR in MySQL?

I have a PK of (id1, id2, col4, col5) This query successfully uses my index except for the last LIKE (which is very usable): SELECT * FROM table1 WHERE id1 = 2 AND id2 = 1 AND col4 LIKE 'min%' AND col4 LIKE '%hou%' I'm wondering how to rewrite…
Shaun
  • 2,043
  • 3
  • 27
  • 36
1
vote
3 answers

Sorting SQL Server records by number of OR conditions matched

Suppose I have a (code-generated) query that is looking for keywords in a number of different fields. For example, any one of the terms University, South or Africa might be in the name field, or the address field, or some other field. I want to find…
Jordan Reiter
  • 20,467
  • 11
  • 95
  • 161
1
vote
0 answers

How to query mongodb with “like” for number data type?

I need to query mongodb use 'like' clause (as in sql) for number data type. At the glance my problem is similar to this question: How to query MongoDB with "like"? The solution given there works perfectly for string datatype since it uses regex.…
Jon Kartago Lamida
  • 827
  • 1
  • 7
  • 12
1
vote
1 answer

MySQL CASE to update one column from multiple columns + LIKE

I was wondering if this is possible to update one column from values in different other columns... something like: UPDATE table SET column1 = CASE column2,column3 WHEN column2 == test AND column3 == 1 THEN 100 WHEN (column2 LIKE…
Snipchain
  • 147
  • 2
  • 12
1
vote
1 answer

SQL Pivot to Return Distinct Values as Column Name

I have a table column with this structure: |------ ID ------| |- 1.20.10.00 -| |- 1.20.10.10 -| |- 1.20.10.20 -| |- 1.20.20.00 -| |- 1.20.20.10 -| |- 1.40.10.00 -| |- 1.40.20.00 -| |- 1.60.10.00 -| |- 1.60.10.00 -| I am trying to…
thefreeline
  • 621
  • 1
  • 12
  • 26
1
vote
1 answer

SQL Like function for Uppercase letters with or without a dash

Using SQL I'm trying to verify that a field contains only UPPERCASE characters, numbers and may contain a '-'. I'm trying to weed out results that have lowercase characters or any symbol other than the '-'. So far I have WHERE ItemCode LIKE…
MikeR
  • 25
  • 1
  • 7
1
vote
2 answers

MySQL SELECT "LIKE" parameter not working properly

I am building a search function in my "search.php" for a database in which I am storing information on ip-addresses and various units. Each unit has a "category" column in the database. My search choices are either searching in a text field, and/or…
Anen
  • 15
  • 1
  • 3
1
vote
1 answer

PostgreSQL hstore: improve LIKE performance with index?

I have a large set of denormalized data with uneven attributes (some attributes are there, some are not) and insert it into a single hstore column. This column contains around 300 key/value pairs with a total size of 5000 chars per row. I wanna do…
Peter
  • 13
  • 4
1
vote
3 answers

oracle select like as column

Hi I need to correct this query, which ends with error: missing right parenthesis what's nonsense, problem is probably somewhere else SELECT name, (name LIKE '%adam%') AS score FROM names ORDER BY score DESC If is not possible use…
user5332
  • 758
  • 2
  • 9
  • 17
1
vote
2 answers

does not work request

What am I doing wrong in my query? thank you in advance for your help new - not work $query = "SELECT * "; $query .= "FROM photographs "; $query .= "WHERE `caption` LIKE '%".$query."%' "; $query .= "OR `caption2` LIKE '%".$query."%'…
Mantykora 7
  • 173
  • 2
  • 8
  • 19
1
vote
1 answer

Is it possible to use commodin in the left side of a LIKE operator?

Is there a way to be able to use at least _ in the left side so the following statement returns 1: SELECT 1 FROM DUAL WHERE 'te_ephone' like 'tele_ho%' I want oracle to parse the left side as it parses the right one, to make _ match 'any' char. Is…
Mario Corchero
  • 5,257
  • 5
  • 33
  • 59
1
vote
1 answer

How can I integrate a parameter list into the LIKE clause?

This code works when I list the codes as written in parm_list_a. However, I'd like to implement like as shown in parm_list_b. What can I do to get this code to work using parm_list_b set serveroutput on; declare parm_list_a varchar2(100) :=…
zundarz
  • 1,540
  • 3
  • 24
  • 40
1
vote
1 answer

Selecting values from a query that are negative in Sybase

Im running the query SELECT ART_REF FROM tablename WHERE SEMESTER_NUM=28 This query returns both positive negative a 0 results in the forms of 8, -2, 0. how can i just return the values that are negative (-8)? I've tired using the LIKE operator…
rkyyk
  • 163
  • 2
  • 5
  • 13
1
vote
2 answers

Mysql LIKE vs REGEXP with 2 or more param

Which would be faster and better on large data? SELECT * FROM 'table' where name LIKE 'micky%' OR name LIKE 'molly%' SELECT * FROM 'table' where name REGEXP '(^micky | ^molly)' When the parameters more than 10, will it make the slower one become…