August 1, 2011 at 1:27 am
Hi
i have this sp,
i have a problem with its result, i want to have 3 records in result order by "Type_ID"but it gives me order by "News_ID"would you please help me?
select *
from News inner join NewsType on NEWS.Type_ID=NewsType.Type_ID
where News_ID in (select MAX(News_ID) from News where Type_ID=1 and GeneralSport=0)
UNION
select *
from News inner join NewsType on NEWS.Type_ID=NewsType.Type_ID
where
News_ID in (select MAX(News_ID) from News where Type_ID=2 and GeneralSport=0 )
union
select *
from News inner join NewsType on NEWS.Type_ID=NewsType.Type_ID
where
News_ID in (select MAX(News_ID) from News where Type_ID=3 and GeneralSport=0 )
August 1, 2011 at 2:18 am
Without seeing the tables, data, or requirements this is difficult.
Try this: -
SELECT *
FROM (SELECT *
FROM news
INNER JOIN newstype ON news.type_id = newstype.type_id
WHERE news_id IN (SELECT MAX(news_id)
FROM news
WHERE type_id = 1 AND generalsport = 0)
UNION
SELECT *
FROM news
INNER JOIN newstype ON news.type_id = newstype.type_id
WHERE news_id IN (SELECT MAX(news_id)
FROM news
WHERE type_id = 2 AND generalsport = 0)
UNION
SELECT *
FROM news
INNER JOIN newstype ON news.type_id = newstype.type_id
WHERE news_id IN (SELECT MAX(news_id)
FROM news
WHERE type_id = 3 AND generalsport = 0))
ORDER BY type_id
August 1, 2011 at 2:39 pm
I started write a refutation of just about everything Joe wrote, because he's wrong at just about every level, even his use of English, but then I decided not to bother. Too much work to point out all the errors, too little payoff.
So, I'll just give my usual, "Please ignore the rabid chimpanzee in the corner. It means well, but it is, after all, a rabid chimp."
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
August 1, 2011 at 2:43 pm
GSquared (8/1/2011)
I started write a refutation of just about everything Joe wrote, because he's wrong at just about every level, even his use of English, but then I decided not to bother. Too much work to point out all the errors, too little payoff.So, I'll just give my usual, "Please ignore the rabid chimpanzee in the corner. It means well, but it is, after all, a rabid chimp."
LMAO!!! Gus, I too started writing a nasty gram but decided it wasn't worth it. 😛
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
August 1, 2011 at 7:37 pm
Heh... Joe who? 😉
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply