Home > SQL Development > [Query - General] And/or

[Query - General] And/or



I'm doing a very simple search, however I'm running into an issue.



SELECT * FROM tbl_users WHERE usrType=0 AND usrFNAME LIKE '%[SEARCH_VAR]%' OR usrLName LIKE '%[SEARCH_VAR]%'



...Where SEARCH_VAR is some user entered keyword(s).



Problem is it not only returns matches where usrType=0, but also matches where usrType=1.



I'm sure I'm missing something basic here...

    
Guest


I think you need to use brackets to seperate the different conditions:


Code:



SELECT * FROM tbl_users WHERE usrType=0 AND (usrFNAME LIKE '%[SEARCH_VAR]%' OR usrLName LIKE '%[SEARCH_VAR]%')



Was this answer helpful ? Yes No   
Guest
 
 
Home - About Infoqu - Contact - Privacy Statement - Link to Infoqu - Bookmark Infoqu

Copyright 2007-2008 by Infoqu. All rights reserved