Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes JDBC and the fly likes How to use the SQL key word EXISTS? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to use the SQL key word EXISTS?" Watch "How to use the SQL key word EXISTS?" New topic
Author

How to use the SQL key word EXISTS?

Mark Lau
Ranch Hand

Joined: Dec 15, 2001
Posts: 120
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

Joined: Dec 02, 2001
Posts: 1
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

Joined: Dec 15, 2001
Posts: 120
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to use the SQL key word EXISTS?