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
1 answer

MySQL Filter certain values from a column containing different data types

There are two main tables. I am providing the necessary columns. Designers with Category | deisgnID Impressions with recId | impressionType | impressionId | impressionAction | session_id Here is a sample session from the sessions . The…
eager_learner313
  • 97
  • 1
  • 3
  • 11
1
vote
1 answer

In Windows8 App-Sqlite safely using string values with LIKE?

I tried this command: List find_person = database.Query("Select * from Person where person_name like '%"+textbox.tex+'%" or person_surname like '%"+textbox.tex+'%" "); But this way is not safe as you know. Is there any way to…
BlackCode
  • 103
  • 11
1
vote
1 answer

How to add the parameter with Like operator in Stored Procedure?

How to add the @id parameter with Like operator after + sign in Stored Procedure? My Query: create procedure gen_report_sp(@id int) as begin insert into report select * from cache where id like (@id+’%’) end Image:
Sathiya
  • 157
  • 1
  • 2
  • 10
1
vote
2 answers

Finding which column matched a LIKE out of multiple LIKE clauses?

SELECT COUNT(news_id) AS count FROM fusion_news WHERE (news_subject LIKE '%новым%' || news_news LIKE '%новым%') Is there a way I can use an alias or set some flag to see which column matched? Currently I'm just doing a manual check in PHP after…
meder omuraliev
  • 183,342
  • 71
  • 393
  • 434
1
vote
1 answer

DB2 query optimization; LIKE alternative

I'm looking to do a wildcard search but I'm noticing some performance degradation on some particular strings(those that initially return a large number filtering down to few). SELECT tbl_1.KEY , tbl_1.USERID ,…
crownedzero
  • 496
  • 1
  • 7
  • 18
1
vote
1 answer

SQL Update table1.column1 if table1.column2 like table2.column2

I have two tables. Products P1 and Manufacturers M1. I want to see if the manufacturer_name is in the P1.title and update the P1.manufacturer_id with the M1.manufacturer_id. UPDATE products P1 set P1.manufacturer_id=manufacturers.manufacturer_id…
1
vote
1 answer

Like operator and Trailing spaces in SQL Server

This one matches column_name like 'CharEndsHere%' and This one doesn't column_name like 'CharEndsHere' I know that like operator will consider even the trailing spaces, so I just copied the exact column value (with trailing spaces) and pasted it.…
Vignesh Paramasivam
  • 2,360
  • 5
  • 26
  • 57
1
vote
1 answer

LIKE operator in SQL Server

I want to get all the records from the one table which contain at least one word from the input string. For example, input parameter='Stack over flow': select * from sample where name like '%stack%' or name like '%over%' or name like…
Geeth
  • 5,282
  • 21
  • 82
  • 133
1
vote
1 answer

SQL LIKE returns wrong results and double rows

My query (this gives me a correct output) SELECT CONCAT(Category.CategoryName, ': ',Product.ProductName) AS SearchOut, Product.ProductID FROM Product ,Category ,ParentCategory ,ProductCategory WHERE ParentCategory.ParentCatID =…
Madde Persson
  • 413
  • 1
  • 6
  • 26
1
vote
2 answers

TSQL Like query in an "in" query

I have a query like the following: select * from table1 where desc in (select field1 from table2) here is the kicker though. I want all the values in the "in" query to be likes. Sort of like the following: select * from table1 where (desc like…
Brian Kalski
  • 897
  • 9
  • 35
1
vote
1 answer

Django creates incorrect MySQL LIKE statement

I am using Django for an application that uses a simple filtering system. I want the filter to test if the title of my model contains a query string. The code, stripped down, looks like this: cards =…
Cosmin Stamate
  • 145
  • 1
  • 1
  • 11
1
vote
2 answers

SQL LIKE partial match from string

I need do searching from longer string. In sql in locality is 'London' and i need use LIKE and string of more cities how in example.. This doesnt work. Please help me, thanks $result = mysqli_query($con, "SELECT * FROM automoto WHERE (title LIKE…
user3780933
  • 11
  • 1
  • 1
  • 4
1
vote
1 answer

MySQL.. search using Fulltext or using Like? What is better?

I'm working on a search feature for my application, I want to search all articles in the database. As of now, I'm using a LIKE in my queries, but I want to add a "Related Articles" feature, sort of like what SO has in the sidebar (which I see as a…
BDuelz
  • 3,890
  • 7
  • 39
  • 62
1
vote
1 answer

MySQL LIKE from JOIN clause and GROUP_CONCAT returns only one row from joined table

I have 3 tables: regions, realestate and one-to-many realestate_regions table. I need to search realestate by address. I have following select query: SELECT re.id, GROUP_CONCAT( r.name ) AS address FROM realestate re JOIN realestate_regions rr ON…
ruuter
  • 2,453
  • 2
  • 30
  • 44
1
vote
1 answer

Selecting rows using multiple LIKE conditions from a table field

I created a table out of a CSV file which is produced by an external software. Amongst the other fields, this table contains one field called "CustomID". Each row on this table must be linked to a customer using the content of that field. Every…
Silver
  • 13
  • 2