Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
select empname from emp where city

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
kalaignar_S
Warnings : 1

New User


Joined: 06 Jan 2006
Posts: 21

PostPosted: Thu May 25, 2006 11:18 am    Post subject: select empname from emp where city
Reply with quote

HI,

i have two queries

1. select empname from emp where city = 'CHENNAI' order by city
2. select empname from emp group by city having city in 'CHENNAI'.


Which one will run fast..


Thanks
Kalaignar
Back to top
View user's profile Send private message

hikaps14

Active User


Joined: 02 Sep 2005
Posts: 189
Location: Noida

PostPosted: Thu May 25, 2006 11:41 am    Post subject: Re: DB2
Reply with quote

Hi ,

i guess most probably the first querry will run faster .

its because it will staright away scan those rows where city = chennai .

where as in 2nd querry

it will first group by for all different cities .
so it will scan more rows n then it will imply the having condition .

i haven't tried these querry out .

it will be better if some one has practical results .

PLZ do correct me if u find me wrong .

Thanks ,
-Kapil .
Back to top
View user's profile Send private message
manisha-s
Warnings : 1

New User


Joined: 22 May 2006
Posts: 13

PostPosted: Thu May 25, 2006 12:16 pm    Post subject: re:DB2
Reply with quote

Using the WHERE clause appropriately can eliminate unnecessary rows before they get to the GROUP BY and HAVING clause, saving some unnecessary work, and boosting performance.

For example, in a SELECT statement with WHERE, GROUP BY, and HAVING clauses, here's what happens. First, the WHERE clause is used to select the appropriate rows that need to be grouped. Next, the GROUP BY clause divides the rows into sets of grouped rows, and then aggregates their values. And last, the HAVING clause then eliminates undesired aggregated groups. If the WHERE clause is used to eliminate as many of the undesired rows as possible, this means the GROUP BY and the HAVING clauses will have less work to do, boosting the overall performance of the query.


so i think where clause with order by run faster as compared to group by with having clause .
Back to top
View user's profile Send private message
humpty
Warnings : 1

New User


Joined: 01 May 2005
Posts: 23

PostPosted: Thu May 25, 2006 5:03 pm    Post subject:
Reply with quote

right manisha,

The WHER clause will extract all the cities with CHENNAI and then sort the intermediate table based on the ORDER BY clause.

but in the case of GROUP BY, first the sorting will take place and then the selection, therefore there will be wastage of time in sorting and then making selection as in case 2, as compare to case first where the selection will be made in advance and then there will be sorting on very less number of selected records.

thanks.[/b]
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Can we limit length in concatenation ... balaji81_k DB2 7 Tue Aug 22, 2017 2:50 am
No new posts Select numeric portion from CHAR data... balaji81_k DB2 6 Sat Aug 19, 2017 1:51 am
No new posts SQL - select data available in index Nileshkul DB2 3 Mon Jun 26, 2017 1:30 am
No new posts Two Selects in a single select query Rohit Umarjikar DB2 1 Fri Nov 04, 2016 8:46 pm
No new posts Select first 2 group data vice_versa DFSORT/ICETOOL 10 Mon Jun 13, 2016 2:21 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us