
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Retrieve from MySQL only if it contains two hyphen symbols?
For this, use the LIKE operator. Let us first create a table:
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Password varchar(100) ); Query OK, 0 rows affected (1.27 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(Password) values('John@--123'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable(Password) values('---Carol234'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(Password) values('--David987'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(Password) values('Mike----53443'); Query OK, 1 row affected (0.30 sec)
Display all records from the table using select statement:
mysql> select *from DemoTable;
Output
+----+---------------+ | Id | Password | +----+---------------+ | 1 | John@--123 | | 2 | ---Carol234 | | 3 | --David987 | | 4 | Mike----53443 | +----+---------------+ 4 rows in set (0.00 sec)
Following is the query to retrieve from MySQL if it only contains two hyphen symbols -
mysql> select *from DemoTable where Password like '%--%' and password not like '%---%';
Output
+----+------------+ | Id | Password | +----+------------+ | 1 | John@--123 | | 3 | --David987 | +----+------------+ 2 rows in set (0.06 sec)
- Related Articles
- REGEX in MySQL to display only numbers separated by hyphen.
- MySQL - Select all records if it contains specific number?
- Only update the MySQL field if the field contains null or 0?
- Select all records if it contains specific number in MySQL?
- Is it possible to check if a String only contains ASCII in java?
- Select a value from MySQL database only if it exists only once from a column with duplicate and non-duplicate values
- MySQL query to retrieve only the column values with special characters?
- Retrieve time from MySQL as HH:MM format?
- Create view in MySQL only if it does not already exist?
- MySQL query to check if a certain row has only two words?
- Can variables have symbols in it like the percentage symbols %?
- Check if the String contains only unicode letters in Java
- Java Program to validate if a String contains only numbers
- How to check if a Python string contains only digits?
- How to check if a string contains only decimal characters?

Advertisements