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

MySql find a value in a comma separated set

I have values stored like this in a field 1,255,230,265. Is there a function in MySQL that will give me the second value in that string? In this case it'll be 255. I tried using locate, but that does not seem to be meant for this.
Norman
  • 6,159
  • 23
  • 88
  • 141
1
vote
5 answers

MySql Query on parts on string

The name column contains items like 'John Smith', 'Elsa John Sanders', 'LilJohn Thomson', 'John'. How can I structure a query just to return the names with John but not LilJohn. I cannot do a LIKE '%John%' as it would return 'LilJohn Thomson'.
Nemo
  • 24,540
  • 12
  • 45
  • 61
1
vote
3 answers

Select a value on multiple columns using like

i have a names table containing 4 columns id fname mname lname 1 rain santos reyes 2 rocky blunt simon 3 greg hammer go then i want to select a particular name from the columns fname, mname…
user3117337
  • 213
  • 1
  • 5
  • 17
1
vote
1 answer

SQL: "Strict equals" doesn't work with LIKE % if last repeats a few times

Among my DB columns there are the columns "tags" and "city". Because I need the search of exact words I'm using LIKE % a few times in the WHERE clause i.e. SELECT ... WHERE `tags` LIKE '$keywords %' OR `tags` LIKE '% $keywords %' OR `tags` LIKE '%…
stckvrw
  • 1,689
  • 18
  • 42
1
vote
2 answers

SQL Not Like Does Not Appear to be Working

What am I doing wrong? I am tearing my hair out here! I have two tables from different servers, linked by an ID field. basically in one server the a colour is recorded properly (white, black etc.) however in the second the colour is recorded with a…
Steven Wood
  • 2,675
  • 3
  • 26
  • 51
1
vote
2 answers

Query Column1 on the basis of Column2 of another table

I need something like: SELECT * FROM Table1 WHERE Name LIKE %Table2.Name%
simone
  • 801
  • 2
  • 13
  • 25
1
vote
2 answers

mysql like query with special character '

I wrote query for filter data using name and wrote following query SELECT * FROM (`abc`) WHERE (name LIKE "%test\'!&@#$\%-(3)\_er%") It should return records which has name start with text "test" but it will not instead of if I modify query like…
priyanka patel
  • 617
  • 2
  • 10
  • 30
1
vote
1 answer

Update statement not working in SQL stored procedure

UPDATE rptMaster SET nQtyOnHand = (select (QTYONHND / rptMaster.UOMQTY) from itemMaster where LOCNCODE = '001' and itemMaster.ITEMNMBR = CASE WHEN rptMaster.ITEMNMBR like '%P' THEN SUBSTRING(rptMaster.ITEMNMBR, 1,…
Anirudh
  • 581
  • 5
  • 14
  • 32
1
vote
1 answer

I'm using Yii addColumnCondition and want to change the default behaviour from '=' to using LIKE and %

I'm using the addColumnCondition function as I like how it forms the queries for multiple queries. But I can't find anything in the documentation to change it's comparison operation from the simple = needle to a LIKE %needle%. There is a function…
Prathamesh Datar
  • 375
  • 1
  • 4
  • 20
1
vote
1 answer

Mysql "like" get most relevant multiple searchwords results

I want a query that would return most close to the keywords from the search field. I search in 4 columns. title, description, author, take_place. This is the current code, that returns results from all columns. i want a more specific search…
DecoderNT
  • 1,054
  • 10
  • 19
1
vote
5 answers

SQL LIKE only one letter

When i use LIKE statement in my SQL, for example, SELECT * FROM table WHERE name = "%k" It will return all rows, where name ends on k. It can return : Ok, OOk, OOOk, How i can do same statement but with one letter, so it returns only Ok. Or…
user3090649
  • 1
  • 1
  • 2
1
vote
3 answers

like and not like in mysql query

I want to do a query containing 'like' and 'not like'. Current query: SELECT * FROM `final` WHERE ( `T_Degree` LIKE '%Keyword1%' ) and (`A_Author_Translator_State` NOT LIKE 'Keyword2' or `T_Author` NOT LIKE 'Keyword2' or…
1
vote
3 answers

Avoiding LIKE Operator in SQL Queries

Is there any other way I can write the query for avoiding using "LIKE" operator, as LIKE usage effects Performance while searching large amount of data. My Table: Products -------- Id int ProductName NVARCHAR(255) Qry: Seraching for products which…
SESHI
  • 33
  • 2
  • 7
1
vote
4 answers

search a single word in mysql

below i mentioned my search page coding. its working fine. but i have a small problem. for example if users selects Guest Name from combobox and then type the query name (for example i stored Rahul Dravid in my mysql db) in input text box. if they…
Karuppiah RK
  • 3,894
  • 9
  • 40
  • 80
1
vote
2 answers

Using NOT LIKE in Filter property of a VBA Recordset

I am using Excel 2003 to connect to a SYBASE database using a VBA recordset. I want to filter the records. The following is code I have used. Dim rset As New ADODB.Recordset rset.Open sQuery, m_db, adOpenForwardOnly rset.Filter = "Name NOT LIKE…
Sambhaji
  • 990
  • 5
  • 19
  • 31