Pattern in Where clause : Patterns « Regular Expression « SQL / MySQL






Pattern in Where clause

    
/* Prepare the data */ 
DROP TABLE Student;

CREATE TABLE Student (
   StudentID INT NOT NULL PRIMARY KEY,
   Name      VARCHAR(50) NOT NULL
)TYPE = InnoDB;


/* Insert data for testing */ 
INSERT INTO Student (StudentID,Name) VALUES (1,'Joe Wang');
INSERT INTO Student (StudentID,Name) VALUES (2,'Cory But');
INSERT INTO Student (StudentID,Name) VALUES (3,'JJ Harvests');
  
/* Real command */
SELECT Name FROM Student
WHERE Name REGEXP '^[J].*r$';

           
         
    
    
    
  








Related examples in the same category

1.Pattern match: string has 5 characters
2.Pattern match: letter repeats
3.Using Pattern Matching
4.Pattern Matching
5.Show records where the name matches a search pattern
6.Matching Pattern Metacharacters Literally
7.To match a literal instance of a SQL pattern metacharacter, precede it with a backslash:
8.To make a pattern match case sensitive, use a binary string for either operand
9.Pattern Matching with Regular Expressions