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

How escape without using replace function in LIKE with PostgreSQL

Short version: I need a function to escape strings for use in LIKE expressions, so fr_e%d becomes fr\_e\%d. I'm looking for escape the result of a query without the need to use replace. Because in this result I have path with this char _ inside.…
Bebeoix
  • 579
  • 2
  • 5
  • 17
1
vote
4 answers

Mysql LIKE clause find 1 and not 11

First I want to say, I'm sorry if this question have be asked already (haven't been able to find it then). My problem is that I've got a LIKE clause in mysql where I have to find some numbers in a comma seperated row. (Yes I know comma separated…
1
vote
1 answer

How to search values that begin or end with another value that contains % and _ chars?

Consider the following tables : drop table if exists testA; drop table if exists testB; create table testA ( id int, testX varchar(255) ); create table testB ( id int, testY varchar(255) ); insert into testA values ( 1, 'this is a test%' ); …
Alain Tiemblo
  • 36,099
  • 17
  • 121
  • 153
1
vote
1 answer

MySQL: How to check for a specific value in a varbinary type?

I'm working with a table that has a field called other_group_ids that is of type varbinary(255). An example vale of it would be: 3,7,14. I have a query that checks to see if a user is in a certain group. For instance, to check if they're in group 4,…
Smeltdown
  • 354
  • 3
  • 7
1
vote
1 answer

Parameterizing an SQL query which uses the NOT LIKE, " ^ " wildcard?

How can I parameterize the following query? (By the way I'm using a full text indexed table, hence the CONTAINS()) SELECT * FROM Table WHERE CONTAINS(Column, 'cat OR dog') and ((column NOT LIKE '%[^ cat OR dog]%')); This didn't work: DECLARE…
Rachael
  • 1,965
  • 4
  • 29
  • 55
1
vote
6 answers

SQL Search for George vs. Georges

I am trying to do a search query with SQL; my page contains an input field who's value is taken and simply concatenated to my SQL statement. So, Select * FROM users after a search then becomes SELECT * FROM users WHERE company LIKE '%georges…
mousesports
  • 509
  • 1
  • 6
  • 18
1
vote
3 answers

select where string doesn't match exactly

It's my table rows: ++ id ---- text ++++++++++++++ -- 1 ---- '90','80,'50' ----- -- 2 ---- '30','2','1_2' -- -- 3 ---- '10_2','5_3' ----- as you see, text contains 2 types of numbers, one doesn't have underscore, and the other does. I want to…
mrdaliri
  • 7,148
  • 22
  • 73
  • 107
1
vote
1 answer

SQL statement optimization: Why the command runs slow?

I have got three tables that are supposed to be joined, the query looks like this: select distinct a.job from a join b on a.job=b.id join c on c.id =a.path where c.path like '//depot/a/b/c/d/MARSR_CL286896_297899/%'; This query will always…
Chen Xie
  • 3,849
  • 8
  • 27
  • 46
1
vote
1 answer

Mysql Like Syntax

Quick question: How do I mysqli_escape_string a variable enclosed in a like clause? "SELECT * FROM table WHERE name LIKE '%". %s . "%'" or "SELECT * FROM table WHERE name like '%"."%s"."%'" don't work. Thanks!
Dirk
  • 6,774
  • 14
  • 51
  • 73
1
vote
1 answer

PDO LIKE query not returning results

Well, I've been at this for a few hours, and for the life of me I can't figure out what is wrong. The code is as follows: $str = "%" . $_POST['str'] . "%"; $offset = (int) $_POST['offset']; try { $stmt = $dbh->prepare("SELECT * FROM Spells…
Daedalus
  • 7,586
  • 5
  • 36
  • 61
1
vote
1 answer

Add wildcard in join condition

How do I add wildcards % to the "specifications.sn" ? SELECT `products2`.`type`, `products2`.`sn`, `products2`.`lap`, `specifications`.`year` FROM `products2` INNER JOIN `specifications` ON `products2`.`sn` LIKE…
user1273409
  • 39
  • 3
  • 9
1
vote
2 answers

Hibernate Criteria API condition "like" with integer

In my database I have a column "year" which is an integer. How can I search by using Criteria API (not by HQL) which records contain, for example "196..." in the year column? I think it should be Restrictions.like, but I got exception: SEVERE:…
Cichy
  • 1,319
  • 3
  • 20
  • 36
1
vote
1 answer

using mysql concat and searching for that field using like, does that work?

I am creating a query like the following SELECT CONCAT(u.firstName," ",u.lastName) as user then later on in the query I write: WHERE user LIKE '%jay%' I am getting no results. Are you not able to use a concatenated field this way?
user1214633
  • 647
  • 1
  • 6
  • 6
1
vote
1 answer

Using LIKE inside an IF in mysql

I'm trying to use LIKE inside an IF clause in mySQL and getting an error. SELECT nc.web_name AS company_name, IF((b.booth_number LIKE '%Cafe%', b.booth_number, substring(b.booth_number,4)) AS booth_number, nc.site_url AS website, IF…
EmmyS
  • 11,892
  • 48
  • 101
  • 156
1
vote
1 answer

Regarding mysql where clause with empty string

My query SELECT order_id, order_item_id, product_id, date_due, ship_via FROM order_shipment WHERE (product_id LIKE 'PP80403396-502%%' AND ship_via != ''); OR SELECT order_id, order_item_id, product_id, date_due, ship_via FROM…
user1558426
  • 13
  • 2
  • 8
1 2 3
99
100