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
12
votes
2 answers

Microsoft office Access `LIKE` VS `RegEx`

I have been having trouble with the Access key term LIKE and it's use. I want to use the following RegEx (Regular Expression) in query form as a sort of "verfication rule" where the LIKE operator filters my results: "^[0]{1}[0-9]{8,9}$" How can…
Tamir
  • 123
  • 1
  • 1
  • 4
12
votes
7 answers

Laravel where like not working properly

I would like to use the query builder with the LIKE operator but it's not working properly. Here is my code in my controller : public function listall($query) { $Clubs = Club::where('clubs.name', 'like', "%$query%") …
12
votes
2 answers

SELECT * FROM tbl WHERE clm LIKE CONCAT('%',,'%') - HOW?

How can I combine those two queries into one? 1) This finds the japanese sign for dog (犬): SELECT japanese FROM edict WHERE english LIKE 'dog' LIMIT 1; 2) This finds all japanese words with the sign for 'dog' (犬) in it: SELECT japanese …
ajo
  • 1,045
  • 4
  • 15
  • 30
12
votes
1 answer

R join on like/grep condition

I am looking for efficient way to join 2 data.frames/data.tables on character column using grep/like/stri_detect condition. I am able to use sqldf package with join on like, but is pretty slow. On my 2 data.tables (5k rows, 20k rows) it takes about…
Kacper
  • 185
  • 9
12
votes
5 answers

SQL query to match one of multiple strings

I have following data in table: +----------------------+----------------------------------------------------------+--------------+ | subscriber_fields_id | name | field_type …
Muhammad Taqi
  • 5,356
  • 7
  • 36
  • 61
12
votes
4 answers

MySQL LIKE statement to find a substring at any location except the start of the string

I have a SQL query SELECT * FROM table WHERE column LIKE '%pdd%'. The problem is I need to get all results excluding those which start with "pdd", by which I mean find everything where "pdd" is not at the beginning. How could it be done? I do need…
Anthony
  • 681
  • 3
  • 9
  • 20
12
votes
4 answers

MySQL - Remove substring from an entry

My 'Location' table contains 6 columns. (ID, Name, Alias, Area, X, Y) Example of some entries from the 'Name' column: Blackwood Highschool, Paris, France Hilltop Market, Barcelona, Spain Roundwell Plaza, Melbourne, Australia Rurk Mount, Moscow,…
Mazka
  • 309
  • 1
  • 4
  • 14
11
votes
3 answers

Postgres case insensitive searching with Rails

My development database is SQLite but I deploy my app to Heroku and they are using PostgreSQL. Now sometimes I have two different results coming out if I perform searches because PostgreSQL is case-sensitive but SQLite is not. Shouldn't Rails…
antpaw
  • 15,444
  • 11
  • 59
  • 88
11
votes
3 answers

Optimising LIKE expressions that start with wildcards

I have a table in a SQL Server database with an address field (ex. 1 Farnham Road, Guildford, Surrey, GU2XFF) which I want to search with a wildcard before and after the search string. SELECT * FROM Table WHERE Address_Field LIKE '%nham%' I have…
hwilson1
  • 489
  • 1
  • 6
  • 17
11
votes
5 answers

Hive query with multiple LIKE operators

What would be the right way to write a Hive query with multiple LIKE operators like this: SELECT * FROM some_table WHERE some_col LIKE '%abc%' OR some_col LIKE '%xyz%' OR some_col LIKE '%pqr%' OR ... (some more LIKE statements) I tried doing the…
Shobit
  • 776
  • 1
  • 6
  • 20
11
votes
3 answers

SQL Multiple LIKE Statements

I'm currently working on a report that shows me all postcodes covered by our sales team. Each team covers over 100 postcodes. What I would like to do is create a report that brings back the clients within the postcode. Currently, my code looks like…
RustyHamster
  • 359
  • 1
  • 5
  • 19
11
votes
3 answers

How can I use the Like Operator with a Parameter in a SQLite query?

I can get the result I expect by entering this in LINQPad: SELECT * FROM WorkTable WHERE WTName LIKE "DSD__20090410014953000%" (it shows me the record which has a WTName value of DSD__20090410014953000.xml") But trying to do this programmatically…
11
votes
3 answers

Expression.Like in C#

eg: x=> x.Name = "g" I have code block like this public Expression> SearchExpression() { var c = new ConstantExpression[_paramList.Count]; var b = new BinaryExpression[_paramList.Count]; BinaryExpression…
Hamed F
  • 800
  • 3
  • 11
  • 23
11
votes
2 answers

Why do we need the GLOB clause in SQLite?

I'm an Android developer and recently came across the GLOB clause in SQLite. I cannot understand why we need GLOB given that LIKE is already in place. Both clauses have wildcards to represent single and multiple characters. The only difference is…
kouretinho
  • 2,190
  • 1
  • 23
  • 37
11
votes
2 answers

How to use LIKE on inet field in Postgres

I need to perform the following query: SELECT * FROM users WHERE ip LIKE '88.99.%'; The problem is that the inet datatype does not seems to support wildcards (at least not in the way I have utilized them in the preceding query). What I'd like to…
Aley
  • 8,540
  • 7
  • 43
  • 56