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

SQLite: determining whether any portion of a string contains any one (of multiple) strings returned by a select query

I'm having trouble figuring out how to ask SQLite to return all entries in a table where "column" contains text found in the results of a select statement. I would like it to work a little like this, if this makes any sense: select * from…
user2069730
  • 11
  • 1
  • 3
1
vote
3 answers

MySQL LIKE operators & wildcards

I've been reading tutorials and have learned nothing new. I have a table of customers. The customer's first and last names are stored in separate columns. I want to write a query that can search for customers by name, either first, last or…
I wrestled a bear once.
  • 22,983
  • 19
  • 69
  • 116
1
vote
1 answer

Mysql search engine like and match against

I hate 4000+ adverts on a database. I use a FULLTEXT index on fields title, model and description. In MySQL I change the value of ft_min_word_len from 4 to 3. Actually, all the results are not matched. Here is a simple request : SELECT * , MATCH…
Raphaël
  • 1,141
  • 3
  • 18
  • 32
1
vote
1 answer

MySQL SELECT with LIKE in java Servlet MySQL error

I'm using Java 7 Servlets and Tomcat 7 as server and MySQL as database. I'm trying to do some searching of users, but theres probably some problem in my SQL, can anybody see the problem? The point of it is that lasNameFragment is fragment of last…
user1097772
  • 3,499
  • 15
  • 59
  • 95
1
vote
3 answers

Mysql like clause throwing syntax error?

I am generating the below query as part of our system: SELECT * FROM (`videos`) WHERE ( `videos`.`title` LIKE "%apple%" OR WHERE `videos`.`byline` LIKE "%apple%" OR WHERE `videos`.`description` LIKE "%apple%" ); However, this is…
Hailwood
  • 89,623
  • 107
  • 270
  • 423
1
vote
2 answers

MySQL Behaviour of Wildcard LIKE matching

I have the following data in TableA... ID | Text --------------------------------------------- 1 | let's find this document 2 | docments are closed ...and if I do the following select... select Text from TableA where Text like '%doc%'; ...I seem…
user1236443
  • 549
  • 2
  • 8
  • 19
1
vote
5 answers

sql Like alternate

Is there any other solution available to use instead of Like to match starts with? here is my query to match starts with using like. explain analyze select * from completedcalls where call_id like 'GWYA4NvSLzoIcvA7RAtmn_a9IelwOQeH@209.44.103.3%'; …
sharafjaffri
  • 2,134
  • 3
  • 30
  • 47
1
vote
1 answer

MongoDb LIKE on two fields combined with AND

I'm looking for MySQL's equivalent of SELECT * FROM table WHERE field1 LIKE '%somestring%' AND field2 LIKE '%anotherstring%' I did try a couple of things, including 'field1' => '/somestring/i', 'field2' => '/anotherstring/i' I'm getting no results…
Iano
  • 30
  • 4
1
vote
2 answers

Get all rows not matching with another table

I've a tricky question. I have a table with numbers: 37823782 37823782 37823782 38478934 90003922 And another table with prefixes: 378 3847 384 001 I want to find all numbers matching the longest prefix. I succeded with this code: $result =…
user1274113
  • 436
  • 8
  • 21
1
vote
4 answers

SQL query - LEFT 1 = char, RIGHT 3-5 = numbers in Name

I need to filter out junk data in SQL (SQL Server 2008) table. I need to identify these records, and pull them out. Char[0] = A..Z, a..z Char[1] = 0..9 Char[2] = 0..9 Char[3] = 0..9 Char[4] = 0..9 {No blanks allowed} Basically, a clean record will…
Riaan
  • 3,423
  • 4
  • 30
  • 36
1
vote
1 answer

How to use a text search and parameterized queries in sql without allowing regex injection

So I'm trying to wrap my head around how to combine three conflicting things (bound parameters, regex, partial-match-searching using user input) securely, and I am not sure I have discovered the right/secure way to deal with these things. This…
Kzqai
  • 22,588
  • 25
  • 105
  • 137
1
vote
0 answers

SQL Query LIKE statement

Possible Duplicate: Order of LIKE clause in query when wanting to use multiple terms I am attempting to make a search function on my website. I want to search more than one field. for example: $sql=mysql_query("select * from inventory WHERE MATCH…
alexander7567
  • 665
  • 13
  • 35
1
vote
2 answers

mysql AND statement

I am trying to search through the columns 'product', 'description', and 'keywords' in my database. The problem is that when I type in a word that is in the 'description' or 'keywords' column of the table, but not in the 'product' column, it doesn't…
Jeff Dyer
  • 11
  • 1
1
vote
1 answer

using LIKE and OR in the where clause of select statement result to this ' Too few parameters. Expected 1.'

When I query in my database microsoft access, with this code.. dc.rs = dc.st.executeQuery("select count(*) from Accounts where username like '%"+searchTF.getText()+"%' OR firstname like '%"+searchTF.getText()+"%'"); I got this result, not sure if…
Katherine
  • 573
  • 4
  • 17
  • 43
1
vote
1 answer

Using Full-Text Search instead of "Like '%____%' query

I am quering a table (about 150,000 rows and growing) with a big varchar field (size 2000) which can't be indexed (and there's no point even if it could be). I am using Sql Server 2008. The query I used till now was: select * from tbl_name where…
1 2 3
99
100