April 17, 2011 at 12:57 am
Hi
where is my error?
somthing wrong is happened near UNION !!!!
select Top 1 *
from News
where GeneralSport=1 and Type_ID=1
order by News_ID
UNION
select Top 1 *
from News
where GeneralSport=1 and Type_ID=1
order by News_ID Desc
April 17, 2011 at 3:28 am
You cannot have two ORDER BY statements in a single UNION query.
select Top 1
from News
where GeneralSport=1 and Type_ID=1
order by News_ID
UNION
select Top 1 *
from News
where GeneralSport=1 and Type_ID=1
order by News_ID Desc
What are you trying to do? It seems like you're trying to find the MIN() and MAX() value. Why not using something like the following?
; WITH cte AS
(
SELECT *,
ROW_NUMBER() OVER(ORDER BY News_ID) AS min_id,
ROW_NUMBER() OVER(ORDER BY News_ID DESC) AS max_id
FROM News
WHERE GeneralSport=1 and Type_ID=1
)
SELECT *
FROM cte
WHERE min_id=1 OR max_id=1
As a side note: I strongly recommend to replace SELECT * with the list of named columns.
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply