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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Isn't there a better way to write this query?

Author  Topic 

DvlprWun
Starting Member

2 Posts

Posted - 2012-12-10 : 01:03:07
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
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2012-12-10 : 01:23:48
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

2 Posts

Posted - 2012-12-10 : 01:45:15
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...
Go to Top of Page
   

- Advertisement -