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

Compare values of two columns

Is there a way to compare the values of two columns in MySQL? For example if I have a table: +----------------+ | Col1 | Col2 | |----------------| | abc | 123abc | | def | 234def | | | 123ghi | +----------------+ And I wanted to…
Ben
  • 2,433
  • 5
  • 39
  • 69
1
vote
1 answer

SQL - AND gets ignored after Like STATEMENT

SELECT * FROM cars WHERE carBrand LIKE '%alfa%' OR carModel LIKE '%alfa%' Everything i put after that sentence just gets ignored. I was hoping to be able to do this. SELECT * FROM cars WHERE carBrand LIKE '%alfa%' OR carModel LIKE '%alfa%' AND…
1
vote
4 answers

mysql select count of records from a string which have exact substring

I have the five records which is like below. I need to fetch the data which have 'rock'. So I need the output like this, the output should display the count of 'rock', so according to the above database the output count should be "3" i.e., rec 1,…
GOOG
  • 73
  • 1
  • 9
1
vote
3 answers

Please help search results between MySQL and PHP using the LIKE operator

I am trying to create a search bar on my website to search for users name. When using mysql on my database the code works fine but when I use it on my website the results are not the same or don't work at all. Not sure if there is a setting I'am…
1
vote
2 answers

Is there an exact string compare in T-SQL?

I have searched many answers, but I have not found a solution for the following simple task: I have a lengthy TextString and want to look for an exact match to the string ' Text ' within it. TextString LIKE '% Text %' gives all occurrences of…
alrts
  • 338
  • 5
  • 12
1
vote
2 answers

select statement in where clause sql

What is the problem with my query I can't figure it out. Select id, name, description, road_st, sub_area, area, website, email, category, working_hrs, inside_building, logo, latitude, longitude, geom.STNumPoints() as vertices,…
1
vote
4 answers

SQL Server Performance tips for like %

I have a table with 5-10 million records which has 2 fields example data Row Field1 Field2 ------------------ 1 0712334 072342344 2 06344534 083453454 3 06344534 0845645565 Given 2 variables variable1 : 0634453445645 variable2 :…
TheGeneral
  • 79,002
  • 9
  • 103
  • 141
1
vote
1 answer

Couldn't get correct answer from MySQL LIKE function

I have a row which contains 'asa' string in my MySQL database. Then I am trying to get result from query when input is like that 'asas2s' But I couldn't get result. My query is like that: SELECT * FROM mod WHERE course LIKE '%asa2s%'
user2066448
1
vote
1 answer

'LIKE' operator in SQL query is very slow with pdo_sqlite

I found out that the 'LIKE' operator in a 'SELECT' SQL query is very slow with pdo_sqlite (PHP 5.3 or PHP 5.4). The same query entered in the sqlite3 binary is way faster. Sample code :
pihug12
  • 317
  • 3
  • 14
1
vote
1 answer

SQL_CALC_FOUND_ROWS not working sometimes

$query->select('SQL_CALC_FOUND_ROWS i.title,i.fulltext,i.shorttext'); $query->from('#__items as i'); $query->where('i.shorttext LIKE "%'.$word.'%"); with this condition everything is right and count of rows is real...for example if it…
user3307827
  • 556
  • 1
  • 7
  • 20
1
vote
2 answers

Can't search MS Access database using LIKE with % or *

I am trying to query a MS Access database from my java code and I am having no luck with the % wildcard that I read should work in other posts. The LIKE operator works if I exclude the wild cards from my code and provide the searchText variable with…
1
vote
2 answers

How to use "." in LIKE query?

When i use . operator in LIKE operator query is not selecting any of the records. My query: SELECT * FROM XSP_AssetList_V WHERE AccountID = '5d6b1eab-1697-de11-a2d1-00505617006d' AND PrinterSerialNumber LIKE '%13.12%' How to use . in LIKE?
xrx215
  • 747
  • 6
  • 22
  • 38
1
vote
3 answers

PHP SQLite like slow

I am trying to analyze network traffic. The traffic is saved into an approximately 300MB-SQLite file, which I am trying to comb for keywords. I have about 10 keywords, for which I generate mutations (reverse string, hashes, etc.), which amounts to…
arik
  • 28,170
  • 36
  • 100
  • 156
1
vote
2 answers

How to group using like statement

First time poster here, so be kind... I am trying to create a new column that would group entries from another column that contain strings of text - for example, I would want entries containing "penny" in column A to have the value "Penny" in the…
1
vote
3 answers

Count how many rows that have a special value in a column

I'm trying to count how many rows that have the same value as a variable. Then I wanna echo out the number that is calculated in the mysql query! Is this possible? Here is a image of my…
myhrmans
  • 35
  • 6