mysqlsqlmysql-workbench

SQL SELECT query not working in mysql


I have an sql query:

SELECT * FROM presentations_db.presenters_tbl WHERE e-mail LIKE '%@%';

It does not seem to work and I don't know why. If I remove the WHERE part it works, but includes all records. I only want records that have an e-mail address. I am using mysql workbench. The e-mail field is a VARCHAR(45). It seems so simple but not... There is no feedback or error messages. The result list doesn't even open.


Solution

  • you must wrap the column name with backtick to avoid syntax error.

    SELECT * FROM presentations_db.presenters_tbl WHERE `e-mail` LIKE '%@%
    

    if you don't wrap it with backtick, it will perform artihmetic operation:

    mail is subtracted from e

    causing you to receive this error message: Unknown column 'e' in 'where clause'