Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to use the SQL key word EXISTS?

 
Mark Lau
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use mysql for a web application.
This application requires the customer to log in using his email address and a password.
Now when I get the customer password, I want to check the customer table in my database and see if that e-mail address exists. If it exists, I then check if the password the customer has just entered matches the one in the customer table associated with the e-mail address.
What SQL statement should I use to check if the customer-supplied e-mail address exists in the customer table? I remember there is a SQL key word EXISTS, right? I tried using it like this:
SELECT customer_email FROM customer WHERE EXISTS billclinton@hotmail.com;
But it does not work.
Can any one of you educate me please? Or is there any other better solution for my problem? Thanks a lot.
 
zai pan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Gene Chao:
I use mysql for a web application.
This application requires the customer to log in using his email address and a password.
Now when I get the customer password, I want to check the customer table in my database and see if that e-mail address exists. If it exists, I then check if the password the customer has just entered matches the one in the customer table associated with the e-mail address.
What SQL statement should I use to check if the customer-supplied e-mail address exists in the customer table? I remember there is a SQL key word EXISTS, right? I tried using it like this:
SELECT customer_email FROM customer WHERE EXISTS billclinton@hotmail.com;
But it does not work.
Can any one of you educate me please? Or is there any other better solution for my problem? Thanks a lot.

simply Just use "where customer_email =..." or use key words * like * or * in*
Hope it is help.
 
Mark Lau
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, your idea works. Thanks. An alternative, which I figured out, is to do it like this:
SELECT COUNT(*) FROM customer WHERE customer_email = 'xxx';
If the value returned is greater than zero, then the value exists.
[ March 19, 2002: Message edited by: Gene Chao ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic