1

in my application user can give username or emailid to login how can i write the query like

select username,password from employee
where username='xxxx' or '[email protected]' and password='******' 

how can i write the query so that user can give username or emailid to login. please send query for this problem thank u

1
  • 1
    @surya: then you should do the polite and proper thing and accept the best answer / the one that really solved you problem. To accept the answer, please click on the check mark to the left of the answer below the "0" with the up- and down-arrow. If someone helps you - please be so kind as to accept the answer. Commented Sep 14, 2009 at 9:19

3 Answers 3

4

Solution:

select username,password from employee where (username='xxxx' or username='[email protected]') and password='******'

Why? There was operator precedence bug:

A or B and C === A or (B and C)

When no brackets specified AND operator has 1st priority. In boolean math AND op is like multiplication and OR op like addition in regular math.

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

1 Comment

You are welcome! Question answer mark would be very appreciated :)
0

You have given the query already. The only thing you need to do, is add braces so that the conditiosn are logically grouped together so that ...

Like this:

WHERE ( username = '' and password = '' ) or (email = '' and password = '' )

1 Comment

@surya: then you should do the polite and proper thing and accept the answer - click on the check mark to the left of the answer below the "0" with the up- and down-arrow. If someone helps you - please be so kind as to accept the answer.
0

try this

select username,password from employee 
where (username='xxxx' and password='******') 
or (username='[email protected]' and password='******') 

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.