blogspot visit counter

Tuesday, 25 June 2013

How i can use like keywords in mysql

How i can use like keywords in mysql
Introduction : -

The LIKE operator is commonly used to select data based on patterns. Using the LIKE operator in appropriate way is essential to increase the query performance.

The LIKE operator allows you to select data from a table based on a specified pattern. Therefore the LIKE operator is often used in the WHERE clause of the SELECT statement.

MySQL provides two wildcard characters for using with the LIKE operator, the percentage % and underscore _.

1 : - The percentage ( %) wildcard allows you to match any string of zero or more characters.
2 : - The underscore ( _) wildcard allows you to match any single character.

Example of  MySQL Like

Suppose We Have Table  Like this


Suppose you want to search for file_upload_tab whose first name starts with character ‘ p‘, you can use the percentage wildcard ( %) at the end of the pattern as follows:

SELECT apk_nm,file_url FROM file_upload_tab  WHERE file_url like 'p%'

Oupput as shown below


To search for file_url  whose last name ends with ‘up‘ string e.g., Patterson, Thompson, you can use the % wildcard at the beginning of the pattern as the following query:

Query -:
SELECT apk_nm,file_url FROM file_upload_tab  WHERE apk_nm like '%up'

OutPut as shown below



If you want to search column whose last values is .jad then we use this query

Query is - :

SELECT apk_nm,file_url FROM file_upload_tab  WHERE file_url like '%.jar%

Output as shown below



No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...