dbTalk Databases Forums  

difference between UNION operator and OR in where clause

comp.databases comp.databases


Discuss difference between UNION operator and OR in where clause in the comp.databases forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Mike
 
Posts: n/a

Default difference between UNION operator and OR in where clause - 07-09-2007 , 10:49 AM






Does anyone know the difference between UNION operator and the "OR" in
where clause ?

Thanks ahead.


Reply With Quote
  #2  
Old   
David Cressey
 
Posts: n/a

Default Re: difference between UNION operator and OR in where clause - 07-09-2007 , 11:19 AM







"Mike" <gongweigang (AT) gmail (DOT) com> wrote

Quote:
Does anyone know the difference between UNION operator and the "OR" in
where clause ?

Thanks ahead.

Yes. What makes you think there is any confusion between them?




Reply With Quote
  #3  
Old   
Tonkuma
 
Posts: n/a

Default Re: difference between UNION operator and OR in where clause - 07-09-2007 , 01:21 PM



On Jul 10, 12:49 am, Mike <gongweig... (AT) gmail (DOT) com> wrote:
Quote:
Does anyone know the difference between UNION operator and the "OR" in
where clause ?

Thanks ahead.
If all tables in UNIONed SELECT statements are same, both would
logically produced same result.(UNION ALL may be resulted redundant
rows. So, it might not be possible to replace with OR.)
But, performance may be same or different depending on DBMS which you
are using.
Generally speaking, OR may be not neccesary sort to eliminate
redundant rows which are sometimes neccesary at the time using UNION.



Reply With Quote
  #4  
Old   
Neo
 
Posts: n/a

Default Re: difference between UNION operator and OR in where clause - 07-24-2007 , 05:15 PM



Quote:
Does anyone know the difference between UNION operator
and the "OR" in where clause ?
For example, in RMDBs, if we have the following tables:

T_Person
ID, Name, Age
1, john, 32
2, mary, 25

T_Car
ID, Name, Age
1, Accord, 2
2, Impala, 3

Then, we can ...
SELECT * FROM T_Person
UNION
SELECT * FROM T_Car;

SELECT * FROM T_Person WHERE age=32 OR age=25;

In dbd, all things are represented by nodes, thus people, cars and
ages can be "OR"ed. The following two expressions are equivalent to
above SELECT statements:

(or (get person instance *)
(get car instance *))

(and (get person instance *)
(get * age (or 32 25)))



Reply With Quote
  #5  
Old   
Neo
 
Posts: n/a

Default Re: difference between UNION operator and OR in where clause - 07-24-2007 , 05:22 PM



Quote:
Does anyone know the difference between UNION operator
and the "OR" in where clause ?
For example, in RMDBs, if we have the following tables:

T_Person
ID, Name, Age
1, john, 32
2, mary, 25

T_Car
ID, Name, Age
1, Accord, 2
2, Impala, 3

Then, we can ...
SELECT * FROM T_Person
UNION
SELECT * FROM T_Car;

and also ...
SELECT * FROM T_Person WHERE age=32 OR age=25;

In dbd, all things are represented by nodes, thus people, cars and
ages can be "OR"ed. The following two expressions are equivalent to
above SELECT statements:

(or (get person instance *)
(get car instance *))

(and (get person instance *)
(get * age (or 32 25)))



Reply With Quote
  #6  
Old   
Ed Prochak
 
Posts: n/a

Default Re: difference between UNION operator and OR in where clause - 07-25-2007 , 01:03 PM



On Jul 24, 6:22 pm, Neo <neo55... (AT) hotmail (DOT) com> wrote:
Quote:
Does anyone know the difference between UNION operator
and the "OR" in where clause ?

For example, in RMDBs, if we have the following tables:

T_Person
ID, Name, Age
1, john, 32
2, mary, 25

T_Car
ID, Name, Age
1, Accord, 2
2, Impala, 3

Then, we can ...
SELECT * FROM T_Person
UNION
SELECT * FROM T_Car;

[]

Actually Neo you point out a difference that the original poster might
not be aware of. It would be very difficult to write that union as a
join with a WHERE OR clause. In some DBMS SQL implementations, it
would be impossible.

Ed



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.