Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
mukhan85
Starting Member
46 Posts |
Posted - 2008-06-20 : 10:39:18
|
| Hi folks,I have a question about the performance of the following query:(SELECT name, lastNamefrom Datawhere salary >= 2200)union(SELECT name, lastNamefrom Datawhere salary >= 2200) union(SELECT name, lastNamefrom Datawhere salary >= 2200)How that query works? Is it slow for a larger data? Does it do 3 queries and then combine them?Thank you. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-20 : 10:47:35
|
| i've heard its better to use union all if you're sure the code chunks wont contain duplicate data. B/w why are you using same query thrice seperated by union? or was it just for illustration? |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-06-20 : 10:49:21
|
| Union combines individual query results and remove duplicates. If you are sure that there won't be overlapping records between multiple resultset, you can use UNION ALL instead of UNION.Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-06-20 : 18:15:43
|
| And if you have such a query having different values for salary you should useSELECT name, lastNamefrom Datawhere (salary >= 2200 or salary >= ...)MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|