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

Sql Server's regex LIKE - behaviour clarification?

Someone asked here how to get only values which are a number : So , if the table is : DECLARE @Table TABLE( Col nVARCHAR(50) ) INSERT INTO @Table SELECT 'ABC' INSERT INTO @Table SELECT '234.62' INSERT INTO @Table SELECT '10:10:10:10'…
Royi Namir
  • 144,742
  • 138
  • 468
  • 792
1
vote
2 answers

SQL Server return wrong result when I use LIKE

I created a new DB "TEST", add a new table "tblTest" and 1 column "Name" in it. Insert some records: Minh, Tinh, Justin create database TEST go use test go create table tblTest (Name varchar(50)) go insert tblTest values ('Minh') insert tblTest…
Kelvin
  • 51
  • 5
1
vote
1 answer

sqlite3 database help in improving performance and design

I have a sqlite3 database with this schema: CREATE TABLE [dict] ( [Entry] [CHAR(209)], [Definition] [CHAR(924975)]); CREATE INDEX [i_dict_entry] ON [dict] ([Entry]); it's a kind of dictionary with 260000 records and nearly 1GB of size; I have…
wiki
  • 1,877
  • 2
  • 31
  • 47
1
vote
2 answers

How can I use the LIKE operator to search for a date in a month?

I have the following database structure and I want to select everything from a specific user and month. However it does return the specific user data but all the months. The month i selected in this example is 2014-02 or February 2014 date …
kpp
  • 800
  • 2
  • 11
  • 27
1
vote
4 answers

SQL LIKE to find either -,/,_

Trying to select from table where the format can be either 1/2/2014, 1-2-2014 or 1_2_2014 in a text field. There's other text involved outside of this format but it shouldn't matter, but that's why this is text not a date type. I tried…
Arger
  • 171
  • 1
  • 9
1
vote
1 answer

MySQL SELECT with LIKE, Wildcards and leading zeroes

I have a kind of odd problem. I am programming a controlpanel for a company internal application, that utilizes a MySQL database in the backend. I currently have a statement like this: SELECT * FROM users WHERE ldap_user LIKE '%--Searchterm--%' OR…
T4cC0re
  • 81
  • 1
  • 9
1
vote
1 answer

Using SQL variable in like statement

I have done much research on this but just cannot get it right. I am trying to query an audit trail using the below: declare @batchid char (30) select @batchid='13857584' --enter batch id here declare @occurred int select @occurred='5' print…
user1879840
  • 23
  • 2
  • 5
1
vote
1 answer

PHP MySQL search function

I am doing a blog for a school project and I am just about done, I want to add a search function and I ran in to some problems, it's probably not very hard to solve though. So I will post my code below and explain I guess. Header.php //requierd on…
user3471898
  • 13
  • 1
  • 3
1
vote
4 answers

full text search in codeigniter

I have a query to search keywords using like, but I also want to search full text so I changed it to full text search query, but it doesn't work. The old query that's working fine: $data = $this->db …
Bahrami-Reza
  • 608
  • 2
  • 7
  • 24
1
vote
3 answers

Performance of LIKE 'xyz%' v/s LIKE '%xyz'

I was wondering how the LIKE operator actually work. Does it simply start from first character of the string and try matching pattern, one character moving to the right? Or does it look at the placement of the %, i.e. if it finds the % to be the…
Jugal Thakkar
  • 13,432
  • 4
  • 61
  • 79
1
vote
4 answers

Using SQL - how do I match an exact number of characters?

My task is to validate existing data in an MSSQL database. I've got some SQL experience, but not enough, apparently. We have a zip code field that must be either 5 or 9 digits (US zip). What we are finding in the zip field are embedded spaces and…
user3481644
  • 398
  • 2
  • 12
1
vote
1 answer

LIKE within CASE statemement OracleSQL (SqlDeveloper)

I seem to be getting a syntax error on the case line between phone_number and LIKE. SQLdeveloper say it is expecting a . ( or | with the following statement; SELECT phone_number, last_name, CASE phone_number WHEN phone_number LIKE '590%'…
1
vote
2 answers

sql select where like statement with many OR operands

I am trying to write a simple search function that reads in a string $query. my question is, can I use multiple ORs in a select statement? I am trying to search one string to see if it matches many column values, then print those rows. function…
AngeKing
  • 69
  • 6
1
vote
1 answer

SQL server 2012 error converting date from string when selecting date with like

In my table, I have a datetime NULL field called logDate. The format stored: 2014-03-28 12:24:00.000 I have a form and the log date is one of the fields for searching logs. The user will enter the date like 2014-03-28 So in my SELECT procedure I…
lleoun
  • 477
  • 3
  • 6
  • 15
1
vote
1 answer

mysql query returning incorrect results with multiple LIKE expressions

I am running this query SELECT `contacts`.* FROM `contacts` WHERE ((email NOT LIKE '%domain1%') AND (email NOT LIKE '%domain2%') AND (email NOT LIKE '%domain3%') AND (email NOT LIKE '%domain4%') ) AND ( …
Ram on Rails
  • 1,299
  • 11
  • 25