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

PHP MySQL search over 3 fields in 3 tables

I've got three tables: bands, gigs, and venues. I want to be able to search by band name, band hometown, and venue name. Here's the general idea of what my tables look like: bands ID | NAME | …
Ben Y
  • 1,711
  • 1
  • 25
  • 37
1
vote
5 answers

Compare string against MySQL column

Say I have the following scenario: $string1 = 'This is my string with the city New York in'; $string2 = 'This is my string with the city Los Angeles in'; MySQL-DB: id|city 0|San Diego 1|Memphis 2|Los Angeles 3|Budapest 4|New York How should I…
JohnF
  • 157
  • 3
  • 14
1
vote
1 answer

PDO query returning more values than intended using LIKE CONCAT

I have a code that is supposed to SELECT items from a table where the fields color_base1 and color_base2 are similar to specific colors. However, currently my code is just returning all the fields in my table, kind of ignoring the LIKE I am…
samyb8
  • 2,560
  • 10
  • 40
  • 68
1
vote
1 answer

MySQL WHERE LIKE not working with multiple fields using php and pdo bind

I'm having an issue here with my WHERE LIKE statement. Ideally, I want to be able to search for multiple terms (or just 1 or the other). Right now, for testing purposes, I have this separated in my test form where I choose what type of function I'm…
SiLeNCeD
  • 240
  • 4
  • 13
1
vote
3 answers

Rails 3 regular expression. like in query

I want to query my database table where the age field have a value 24 or 26. I tried using 'like' in my query. User.where('age like ? or age like ?',"%24%","%26%") Am I doing something wrong here?
user1616238
1
vote
2 answers

MYSQL: LIKE (subquery) returning many rows

The following code work's properly. SELECT Message FROM SystemEventsR WHERE Message LIKE CONCAT('%',(SELECT username FROM users LIMIT 1),'%') My question though, is most of the time i need to return more than one row. I omit the LIMIT which…
1
vote
1 answer

In PostgreSQL how to combine NOT IN and LIKE?

How do you combine NOT IN and LIKE? Let's assume we have a table that contains a column of names (something like 'blue cheese', 'gouda cheese' and so on) and I want to select all the names that doesn't contain 'cheese', 'milk', 'meat'. As far as I…
boo_boo_bear
  • 189
  • 1
  • 4
  • 14
1
vote
3 answers

TSql LIKE search on comma delimited data

Quick question on LIKE searches. If I have a column with a value 'Analyst,Trainer' and another column 'Workflow,Analyst,Tester,Trainer', I want to check if the values in the first column are in the second column. We can easily see that the answer is…
David Whitten
  • 573
  • 1
  • 4
  • 12
1
vote
2 answers

PHP MySQL LIKE command not working properly

I am trying to retrieve data from a table based on if the user enters characters in a search bar which match with a variable that holds the description of an item. I am doing this using MySQL in PHP and this is the retrieval code I have so…
Ryman Holmes
  • 746
  • 3
  • 22
  • 40
1
vote
1 answer

Spring JPA @Query where clause with 'like' and 'or'

I have the following query: @Query("select c from Category c where ( (lower(c.name) like '%' || lower(:searchText) || '%') or (lower(c.description) like '%' || lower(:searchText)) || '%')") My product is designed to run in multiple platform, I am…
Fabricio Z
  • 13
  • 1
  • 3
1
vote
1 answer

Cap symbol (^) in LIKE Clause not working properly

See the below example where '1|2|||1|' like '%%|%%|%%|%%|[^3]|' /* it will return true if the string between last two pipe symbols is not like '3'*/ The above code just works fine. In the same way I need to build a expression for the string…
Maximus
  • 792
  • 9
  • 19
1
vote
2 answers

MySQL and PHP - using 'LIKE' AND 'NOT LIKE'

I need some help with using LIKE and NOT LIKE together... I have a query that I pass WHERE clauses through based on what my request variable is from another server. One of the queries is like the following: 'CONNECT' => "(…
brandoncluff
  • 303
  • 1
  • 5
  • 19
1
vote
2 answers

SQL field contains a string (comma delimited or at start/end)

I have a field ERR_CODES on my db that contains some error codes for the current record. For example, it can contain: Invalid_Template_Code_Filename_WCLS,Color_Template_Of_Different_Domain_WCLS,Section_Not_Found_WCLS Suppose I want to test if it…
Teejay
  • 7,210
  • 10
  • 45
  • 76
1
vote
1 answer

Find Top 1 best matching string in SQL server

I have a table 'MyTable' which has some business logics. This table has a column called Expression which has a string built using other columns. My query is Select Value from MyTable where @Parameters_Built like Expression The variable…
Maximus
  • 792
  • 9
  • 19
1
vote
0 answers

Select column from similarly named tables

I want to select a specific column form many tables that have similar names i.e.: Tables Names x1 x2 x3 y1 y2 z1 smth like this : select field from like x%; all tables have the same structure and column names
Krisid Misso
  • 126
  • 1
  • 8