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
4 answers

Oracle "Starts With" text join, excluding nulls

I am having some trouble. I am trying to build a SQL query that uses "starts with" logic. A little background first... In the database that I've been tasked to write reports from, there is a "user" table and a "salesperson" table, with salespersons…
ryvantage
  • 13,064
  • 15
  • 63
  • 112
1
vote
0 answers

The LIKE operator in SOQL does not escape special character

Hi below is my SOQL qoery SELECT ID,Name, Dodge_Report_Number__c,Project_Name__c,Bid_Date__c,GC_Awarded__c,Action_Stage__c,Target_Start_Date__c,Project_Valuation_High__c,Project_Valuation_Low__c,Type_Of_Work__c,Removed_By__r.Name,…
user1841408
  • 133
  • 1
  • 1
  • 8
1
vote
2 answers

LIKE Clause not working due to php variable

this is my code....have tried to echo the $sql but it shows '%Search%'...but i want to use it as $Search .. plz help ... Below is my entire code for search... if(isset($_POST['search'])) …
user2285084
1
vote
2 answers

When selecting rows based on a where clause how can I match full words?

I am trying to create search functionality for a website. In MySQL I would like to match words exactly, for example if I have a couple of posts with these titles: A day in time and A coming day and I have the following search string: SELECT…
crmepham
  • 4,676
  • 19
  • 80
  • 155
1
vote
2 answers

MySQL LIKE more results than expected

Why does this LIKE-statement WHERE configuration_key LIKE 'MODULE_SHIPPING_DP_%' shows results like this: MODULE_SHIPPING_DPD_STATUS MODULE_SHIPPING_DP_STATUS MODULE_SHIPPING_DPD_TAX_CLASS MODULE_SHIPPING_DP_TAX_CLASS I only wanted to get results…
user1286819
  • 101
  • 1
  • 9
1
vote
2 answers

How to use like clause in MySQL 5.0 Statement

I have a problem using 'like' clause in MySQL 5.0 I have written a stored procedure in MySQL 5.0 and calling the Stored Procedure from my Java Program the stored procedure below in the select statement i want to take the value of parameter…
user2200561
  • 21
  • 1
  • 6
1
vote
1 answer

mysql LIKE operator not matching the condition appropriately

I'm using a query such as SELECT * FROM tablename WHERE token LIKE 'v_%' This is resulting in records whose token starts with v_ (which is exactly what I want) but it is also showing records which start with just v (screenshot attached) Why is…
asprin
  • 9,579
  • 12
  • 66
  • 119
1
vote
4 answers

Get rows that contain only certain characters

I want to get only those rows that contain ONLY certain characters in a column. Let's say the column name is DATA. I want to get all rows where in DATA are ONLY (must have all three conditions!): Numeric characters (1 2 3 4 5 6 7 8 9 0) Dash…
no9
  • 6,424
  • 25
  • 76
  • 115
1
vote
2 answers

How to check if parts of a string match to a column data in sql table

I want to write a query which checks the input provided by the user with the column data of my table. i tried using LIKE and CONTAINS but it didnt work for me. eg my table data contains "Bar B Q Tonight" and if user enters "BBQ Tonight", how to deal…
just a learner
  • 57
  • 1
  • 11
1
vote
2 answers

MS-SQL List of email addresses LIKE statement/regex

I have a column in my table called TO which is a comma separated list of email addresses. (1-n) I am not concerned with a row if it ONLY contains addresses to Whatever@mycompany.com and want to flag that as 0. However, if a row contains a NON…
Pythonn00b
  • 325
  • 1
  • 4
  • 20
1
vote
2 answers

How to search all string in MySql that start with a number?

I want to run a mysql query to give me all available results that start with a number. SELECT * FROM users WHERE username LIKE number + '%' I tried using LIKE REGEXP '^[0-9] but it is not working for me
Jaylen
  • 39,043
  • 40
  • 128
  • 221
1
vote
1 answer

Nested Where, Like Or like MySql Query doesn't care about Where Clause

I'm working on a new project, and for this project I need a "search Engine" of shops stored in my database. I make a Like query on the name and the address of the shop, but only where the shop is valid (set to 1). My query looks like that : SELECT *…
BastienPenalba
  • 158
  • 2
  • 10
1
vote
1 answer

Order by random and LIKE

I want to get random row from database, but limit it using some content. For example, table's definition: id | content | tags The query is: SELECT * FROM tbl ORDER BY RAND() LIMIT 1. Tags part looks like: tag1, tag2, tag42. So, for example, I want…
Max Frai
  • 61,946
  • 78
  • 197
  • 306
1
vote
3 answers

Like with right value with wildcard percent

I need to search for countries ids and I ran into a problem, for example, let's take the country "Bolivia". The Country table has a "CountryName" and "Alternative Names" For the example of "Bolivia". IdCountry Name Code …
Mariano G
  • 255
  • 4
  • 14
1
vote
2 answers

Left Join And several LIKE makes my query very slow

I'm making a dictionary and i have two tables word (word, description, ext) translate (id, word_translate, description_tranlate, org_word, language_id) All words are not translated.I want only search for 'word' and 'word_translated'. The search…
teebe
  • 21
  • 1