Sql 中 and ,or 的区别

     

                小朱我那天做程序的时候,发现自己做的程序,怎么总是计算结果有问题,呵呵,原来是把and ,or 没弄明白!

          and

                表示 两者都要满足

         or 满足其中之一,便可

     例子: 我想查询,username 为  张三,或者是李四的信息

         select *from userInfo where username='张三' or username='李四' (大多数的朋友,应该是这样写的吧!)

 

      但是,如果你的where 条件多了,很多的话,呵呵

          select *ffrom userInfo where userid=1 and username='张三' or username='李四'    and so on..(这样的话可能会有问题哦!)

    

       最好这样写

     select *ffrom userInfo where userid=1 and (username='张三' or username='李四' )   and so on..(这样写的话,就没有问题,并且很美观)

 

posted @ 2008-08-19 13:01  文杰  阅读(3731)  评论(0编辑  收藏  举报