MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 1st, 2004, 11:15 PM
jpi1116 jpi1116 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 1 jpi1116 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
query help

Here is a query, I wanted to write optimised query. in the below query I'm executing two times the query "select rid from rtm where tid=3"
How can i re write this query to run only one time. any optimization suggestions are much appriciaated.

Here is the query

select f.pid,f.yearmonth,
rs.rid, p.pnumber,f.fs,
r.function

from f, ( select rID
from RTM
where tid=3 ) as rs, p, r

where rs.rid = r.rid
and f.rid = rs.rid
and p.pid = f.pid
and f.yearmonth between 200405 and 200504
union

select ah.pid, ah.yearmonth, rs.rid,
p.pnumber, ah.ahrs,-1

from ( select rID
from RTM
where tid=3 ) as rs, p, ah

where rs.rid = ah.rid
and p.pid = ah.pid
and ah.yearmonth between 200405 and 200409

order by rs.rid


Here rid,pid are primary key in their respective tables

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > query help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway