2009-09-14 199 views
1

能給用戶名或EMAILID登錄我怎麼可以編寫SQL服務器的SQL查詢

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

我如何編寫查詢的查詢,使用戶可以給用戶名或EMAILID登錄。 請發送查詢這個問題謝謝你

+1

@surya:那麼你應該做的禮貌和適當的事情,並接受最好的答案/真正解決你的問題。要接受答案,請用向上和向下箭頭點擊「0」下面答案左邊的複選標記。如果有人幫助你 - 請儘量接受答案。 – 2009-09-14 09:19:27

回答

0

你已經給出了查詢。 你需要做的唯一的事情,是加括號,使得conditiosn在邏輯上劃分在一起,使...

像這樣:

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

感謝你frederik gheysels這是好的 – 2009-09-14 09:09:29

+0

@surya:那麼你應該做的禮貌和適當的事情,並接受答案 - 點擊上方和下方箭頭「0」下面的答案左邊的複選標記。如果有人幫助你 - 請儘量接受答案。 – 2009-09-14 09:18:50

0

試試這個

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

謝謝你rruz它正在工作 – 2009-09-14 09:07:52

4

解決方案:

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

爲什麼? 有運算符優先級的錯誤:

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

如果未指定括號和運營商具有第一優先。 布爾運算和運算就像常規數學中的乘法和OR運算一樣。

+0

不錯的一個很好的解釋thanku rafal ziolkowski – 2009-09-14 09:08:42

+0

不客氣!問題答案標記將非常讚賞:) – 2009-09-14 22:11:23