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
68
votes
9 answers

SQL SELECT LIKE (Insensitive casing)

I am trying to execute the sql query: select * from table where column like '%value%'; But the data is saved as 'Value' ( V is capital ). When I execute this query i don't get any rows. How do i make the call such that, it looks for 'value'…
user2583714
  • 1,097
  • 2
  • 11
  • 18
68
votes
5 answers

how to use a like with a join in sql?

I have 2 tables, say table A and table B and I want to perform a join, but the matching condition has to be where a column from A 'is like' a column from B meaning that anything can come before or after the column in B: for example: if the column in…
jim
66
votes
2 answers

MySQL: NOT LIKE

I have these text in my db, categories_posts categories_news posts_add news_add And I don't want to select the rows with categories, I use a query something like this, SELECT * FROM developer_configurations_cms WHERE…
Run
  • 54,938
  • 169
  • 450
  • 748
61
votes
4 answers

SQLite Like % and _

I can't figure out what the underscore character does in an SQLite like statement. The wildcard character, %, is probably the same as in most other SQL databases. So, what does the _ character do?
Francisc
  • 77,430
  • 63
  • 180
  • 276
59
votes
2 answers

How can I with mysqli make a query with LIKE and get all results?

This is my code but it dosn't work: $param = "%{$_POST['user']}%"; $stmt = $db->prepare("SELECT id,Username FROM users WHERE Username LIKE ?"); $stmt->bind_param("s",…
user2493164
  • 1,321
  • 3
  • 11
  • 15
58
votes
3 answers

MySQL join query using like?

I have been trying to get this working for quite a while now but it just doesn't seem to work, maybe it is is not even possible, what i am wanting to do is to perform a MySQL join query using like, such as this example i found... SELECT * FROM…
David
  • 969
  • 2
  • 11
  • 17
54
votes
4 answers

NOT LIKE and LIKE not returning opposite result

I have a table with 200 records out of which 10 records has text containing the word 'TAX'. When I'm executing Select * from tbl1 WHERE [TextCol] LIKE '%TAX%' then I get the result set with those 10 records correctly . But when I am trying to…
Shanka
  • 811
  • 1
  • 7
  • 16
53
votes
1 answer

MySQL starts with searching issue

I'm having an issue using the % wildcard with a MySQL query. http://www.w3schools.com/sql/sql_like.asp Having read that article, I am using % and not getting quite what I was expecting. I have a series of values, such as 1_1 1_2 2_1 2_2...…
Jamie Hartnoll
  • 7,231
  • 13
  • 58
  • 97
53
votes
7 answers

'LIKE ('%this%' OR '%that%') and something=else' not working

I have a select query where I am trying to search strings for multiple patterns LIKE ('%this%' or '%that%' ) and something=else Returns zero results However LIKE '%this%' and something=else returns results and LIKE '%that%' and…
Kevin Ohashi
  • 533
  • 1
  • 4
  • 5
53
votes
4 answers

SQL LIKE with no wildcards the same as '='?

I know this is a pretty basic question, and I think I know the answer...but I'd like to confirm. Are these queries truly equivalent? SELECT * FROM FOO WHERE BAR LIKE 'X' SELECT * FROM FOO WHERE BAR ='X' Perhaps there is a performance overhead in…
javamonkey79
  • 17,443
  • 36
  • 114
  • 172
52
votes
5 answers

PostgreSQL: Select data with a like on timestamp field

I am trying to select data from a table, using a "like" on date field "date_checked" (timestamp). But I have this error : SQLSTATE[42883]: Undefined function: 7 ERROR: operator does not exist: timestamp without time zone My request is : SELECT…
Kevin Campion
  • 2,223
  • 2
  • 23
  • 29
51
votes
2 answers

Python SQLite parameter substitution with wildcards in LIKE

I am attempting to use a parametrized LIKE query with Python's Sqlite library as below: self.cursor.execute("select string from stringtable where string like '%?%' and type = ?", (searchstr,type)) but the ? inside of the wildcard is not being…
atcuno
  • 523
  • 1
  • 4
  • 5
51
votes
4 answers

SQL SELECT WHERE string ends with Column

I have this table in SQL Server 2012: Id INT DomainName NVARCHAR(150) And the table have these DomainName values google.com microsoft.com othersite.com And this value: mail.othersite.com and I need to select the rows where the string ends with…
Mario
  • 13,941
  • 20
  • 54
  • 110
51
votes
1 answer

LIKE with % on column names

Here is my query that results in a syntax error: SELECT * FROM account_invoice,sale_order WHERE sale_order.name LIKE %account_invoice.origin% The account_invoice.origin field contains the text of sale_order.name, plus other text as well, so I need…
user1806801
  • 513
  • 1
  • 4
  • 4
50
votes
3 answers

Create hive table using "as select" or "like" and also specify delimiter

Is it possible to do a create table as select using row format delimited fields terminated by '|'; or to do a create table like row format delimited fields terminated by '|'; The Language…
WestCoastProjects
  • 58,982
  • 91
  • 316
  • 560