在MySQL表格中查找无效的电子邮件地址列表?

要查找无效的电子邮件地址,请使用以下语法-

SELECT yourColumnName FROM yourTableName
WHERE yourColumnName NOT LIKE '%_@_%._%';

上面的语法将列出所有无效的电子邮件地址。为了理解上述语法,让我们创建一个表。创建表的查询如下-

mysql> create table FindInvalidEmailAddressDemo
   -> (
   -> Id int NOT NULL AUTO_INCREMENT,
   -> Name varchar(20),
   -> EmailAddress varchar(40),
   -> PRIMARY KEY(Id)
   -> );

现在,您可以使用insert命令在表中插入一些记录。对于我们的示例,我们还插入了一些无效的电子邮件地址。查询如下-

mysql> select *from FindInvalidEmailAddressDemo;

以下是输出-

+----+-------+-------------------+
| Id | Name  | EmailAddress      |
+----+-------+-------------------+
|  1 | John  | John12@gmail.com  |
|  2 | Carol | Carol@hotmail.com |
|  3 | Mike  | 123Mike@gmailcom  |
|  4 | Bob   | Bob909hotmail.com |
|  5 | David | David@gmail.com   |
+----+-------+-------------------+
5 rows in set (0.00 sec)

以下是查找无效电子邮件地址的查询-

mysql> select EmailAddress from FindInvalidEmailAddressDemo
   -> where EmailAddress NOT LIKE '%_@_%._%';

以下是带有无效电子邮件地址列表的输出-

+-------------------+
| EmailAddress      |
+-------------------+
| 123Mike@gmailcom  |
| Bob909hotmail.com |
+-------------------+
2 rows in set (0.00 sec)