dcsimg
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: SQL
Expertise: Intermediate
Nov 5, 2018

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Know if LIKE Results are True or False

MySQL is capable of returning the result of a LIKE directly in the result set itself.

For example, if you use a wildcard character in a query such as below, you get to know if the result is true or false based on the value of the resulting column. If the value is 1, it implies the result is true. If the value is 0, it implies the result is false.

Create code for the table under consideration.

CREATE TABLE `FILEDATA` (
   `ID` INT(11) NOT NULL,
   `FILEPATH` TEXT NOT NULL COLLATE 'utf8_bin'
)
COLLATE='utf8_bin'
ENGINE=InnoDB
;

Data for the table

+-----+-------------+
| ID  |  FILEPATH   |
+-----+-------------+
|  1  | /root       |
|  2  | /opt/tab    |
|  3  | /etc/init.d |
+-----+-------------+

And now, our query.

SELECT FILEPATH, FILEPATH LIKE '/%' FROM FILEDATA

Output:

+-------------+--------------------+
|  FILEPATH   | FILEPATH LIKE '/%' |
+-------------+--------------------+
| /root         |                  1 |
| /opt/tab    |                  1 |
| /etc/init.d |                  1 |
+-------------+--------------------+

Yes, you can try with other options as well. Exploring is good.

M S Sridhar
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date