Apa fungsi perintah like test pada mysql
LoginRegister NOT LIKE operatorMySQL NOT LIKE is used to exclude those rows which are matching the criterion followed by LIKE operator. Syntax: expr NOT LIKE pat [ESCAPE 'escape_char']
% is used to match
any number of characters, even zero characters. To test for literal instances of a wildcard character, precede it by the escape character. If you do not specify the ESCAPE character, “\” is assumed. MySQL Version: 5.6 Example: MySQL NOT LIKE operator with (%) percent The following MySQL statement excludes those rows from the table author, having the 1st character of aut_name ‘W’. Code:
Relational Algebra Expression: Relational Algebra Tree: Sample table: author Sample Output: mysql> SELECT aut_name, country -> FROM author -> WHERE aut_name NOT LIKE 'W%'; +----------------------+-----------+ | aut_name | country | +----------------------+-----------+ | S.B.Swaminathan | India | | Thomas Morgan | Germany | | Thomas Merton | USA | | Piers Gibson | UK | | Nikolai Dewey | USA | | Marquis de Ellis | Brazil | | Joseph Milton | USA | | John Betjeman Hunter | Australia | | Evan Hayek | Canada | | E. Howard | Australia | | C. J. Wilde | UK | | Butler Andre | USA | +----------------------+-----------+ 12 rows in set (0.00 sec) PHP script:
View the example in browser JSP script:
Example : MySQL NOT LIKE operator with ( _ ) underscore The following MySQL statement excludes those rows from the table author having the country name like the above pattern as specified with LIKE operator. Code:
Relational Algebra Expression: Relational Algebra Tree: Sample table: author Sample Output: mysql> SELECT aut_name, country,home_city -> FROM author -> WHERE country NOT LIKE 'U_A' and country NOT LIKE 'C__a_a'; +----------------------+-----------+----------------+ | aut_name | country | home_city | +----------------------+-----------+----------------+ | William Norton | UK | Cambridge | | William Anthony | UK | Leeds | | S.B.Swaminathan | India | Bangalore | | Thomas Morgan | Germany | Arnsberg | | Piers Gibson | UK | London | | Marquis de Ellis | Brazil | Rio De Janerio | | John Betjeman Hunter | Australia | Sydney | | E. Howard | Australia | Adelaide | | C. J. Wilde | UK | London | +----------------------+-----------+----------------+ 9 rows in set (0.00 sec) PHP script:
View the example in browser Online Practice Editor: Slideshow of MySQL Comparison Function and Operators Previous: NOT IN() |