Home » SQL & PL/SQL » SQL & PL/SQL » Logical operations
Logical operations [message #293172] Fri, 11 January 2008 01:34 Go to next message
hidnana
Messages: 87
Registered: November 2007
Location: chennai
Member
Why do these queries return 1 instead of empty row ?
select 1 from dual
where 1=1 or 1=1 or 1=1 and 1=2

select 1 from dual
where 1=2 and 1=1 or 1=1 or 1=1 

Re: Logical operations [message #293175 is a reply to message #293172] Fri, 11 January 2008 01:45 Go to previous messageGo to next message
rajavu1
Messages: 1574
Registered: May 2005
Location: Bangalore , India
Senior Member

These will give desired result once Lgical operators are properly placed .

SQL> select 1 from dual
  2  where 1=1 or 1=1 or 1=1 and 1=2;

         1
----------
         1

SQL> select 1 from dual
  2  where (1=1 or 1=1 or 1=1 )
  3  and 1=2;

no rows selected

SQL> select 1 from dual
  2  where 1=2 and 1=1 or 1=1 or 1=1
  3  ;

         1
----------
         1

SQL> select 1 from dual
  2   where 1=2 and
  3  (1=1 or 1=1 or 1=1)
  4  ;

no rows selected

SQL>


Thumbs Up
Rajuvan.

[Updated on: Fri, 11 January 2008 01:46]

Report message to a moderator

Re: Logical operations [message #293176 is a reply to message #293172] Fri, 11 January 2008 01:47 Go to previous messageGo to next message
Littlefoot
Messages: 20901
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Because of OR.
Re: Logical operations [message #293181 is a reply to message #293172] Fri, 11 January 2008 02:00 Go to previous messageGo to next message
Michel Cadot
Messages: 64139
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
SQL Reference
Chapter 7 Conditions
Section About SQL Conditions
Subsection Condition Precedence

Regards
Michel
Re: Logical operations [message #293184 is a reply to message #293175] Fri, 11 January 2008 02:11 Go to previous message
hidnana
Messages: 87
Registered: November 2007
Location: chennai
Member
Thanks. Now I've understood the precedence in SQL logical operations.
Previous Topic: to_num
Next Topic: Problem in locking
Goto Forum:
  


Current Time: Fri Dec 09 00:00:51 CST 2016

Total time taken to generate the page: 0.09897 seconds