SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Isn't there a better way to write this query?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

DvlprWun
Starting Member

USA
2 Posts

Posted - 12/10/2012 :  01:03:07  Show Profile  Reply with Quote
I'm not as good as I used to be with T-SQL seeing as to how I mainly do Front End nowadays, but I'm trying to get back into SQL and the other parts of the N-tier. I'm making my first attempt at writing an Orchard CMS module and came up with this. It works, but I'm sure it's not the most efficient way to do it. Can someone help me out here?


select top(1)oBody.ContentItemRecord_id, oBody.Text, oRoute.Title
from oCMS__Common_BodyPartRecord as oBody, oCMS__Routable_RoutePartRecord as oRoute
where oBody.ContentItemRecord_id
in (Select top(1) Id from oCMS__Common_CommonPartRecord
where Container_id is not null order by ModifiedUtc desc)

AND oRoute.ContentItemRecord_id in
(Select top(1) Id from oCMS__Common_CommonPartRecord
where Container_id is not null order by ModifiedUtc desc)

order by oBody.Text desc


Thanks for reading!

Killer Coding Ninja Monkeys do Exist...

bandi
Flowing Fount of Yak Knowledge

India
2224 Posts

Posted - 12/10/2012 :  01:23:48  Show Profile  Reply with Quote
select top(1)oBody.ContentItemRecord_id, oBody.Text, oRoute.Title
from oCMS__Common_BodyPartRecord as oBody JOIN oCMS__Routable_RoutePartRecord as oRoute ON oBody.ContentItemRecord_id = oRoute.ContentItemRecord_id
where oBody.ContentItemRecord_id
= (Select top(1) Id from oCMS__Common_CommonPartRecord
where Container_id is not null order by ModifiedUtc desc)
ORDER BY oBody.text DESC

--
Chandu
Go to Top of Page

DvlprWun
Starting Member

USA
2 Posts

Posted - 12/10/2012 :  01:45:15  Show Profile  Reply with Quote
Thanks! That returns the same results.

With that being said, I'm guessing that this is also the most efficient way to do this query:

select idTbl.TagsPartRecord_Id, idTbl.TagRecord_Id, Tags.TagName
from oCMS__Orchard_Tags_ContentTagRecord as idTbl
join oCMS__Orchard_Tags_TagRecord as Tags
on idTbl.TagRecord_Id = Tags.Id
where idTbl.TagsPartRecord_Id = 701
order by idTbl.id desc

Killer Coding Ninja Monkeys do Exist...

Edited by - DvlprWun on 12/10/2012 01:45:52
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000