0

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.

5
  • I have checked the following: Commented Apr 10, 2013 at 14:40
  • e-mail field exists and is spelt correctly. presentations_db.presenters_tbl exists and is spelt correctly. Commented Apr 10, 2013 at 14:41
  • The fact that it works without the WHERE part tells me there must be a problem with the e-mail field, but what?? Commented Apr 10, 2013 at 14:42
  • see my explanation below, it perform arithmetic operation. Commented Apr 10, 2013 at 14:43
  • If possible, I'd recommend changing your column name to e_mail - DB objects whose name contain special characters are always terrible to work with (this also applies to umlauts / accents / case-sensitive names). Commented Apr 11, 2013 at 7:06

3 Answers 3

3

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'


Sign up to request clarification or add additional context in comments.

Comments

0

you query is right just replace this

    e-mail

by this

   `e-mail`

Comments

0

Apart from the required quoting with back-ticks or double quotes (if ANSI quoting is enabled) I'd change the where clause this:

SELECT * FROM presentations_db.presenters_tbl WHERE `e-mail` IS NOT NULL;

since all you want is the records which have an e-mail set. It doesn't check for validity of the address, however.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.