tags:

views:

56

answers:

3

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

A: 

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 = '' )
Frederik Gheysels
thank u frederik gheysels it is good
Surya sasidhar
@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.
marc_s
A: 

try this

select username,password from employee 
where (username='xxxx' and password='******') 
or (username='[email protected]' and password='******')
RRUZ
thank u rruz it is working
Surya sasidhar
+4  A: 

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.

Rafal Ziolkowski
nice one good explanation thanku rafal ziolkowski
Surya sasidhar
You are welcome! Question answer mark would be very appreciated :)
Rafal Ziolkowski