[thelist] SQL Union and order by problem

XtiaN indotekken at yahoo.com
Thu Oct 18 21:28:25 CDT 2007


Actually, i'm using union because i've asked to make web page to view all of our member pictures. We want to display picture in our first page who already being 
registered 3 days ago (subquery asd). And the new member who registered in newest 3 days will be put in last pages.

ex: i have 1000 members registered. 1 page will contain 10 members, so i would have 100 pages. Our member who has registered 3 days before today (<= oct 17th) are 700 members.
Today is Oct 19th. in my first page until page-70, i will list my members pic who already registered 3 days ago (<= oct 17th) and our member who has registered from oct > Oct 17th will be displayed on latest pages


select * From (
SELECT top 100 PERCENT a,b,c    
FROM tb
WHERE DATEDIFF(day, b ,getdate())>=3 
order by b desc) asd 
union all
select * From (
SELECT top 100 PERCENT a,b,c    
FROM tb
WHERE DATEDIFF(day, b ,getdate())<3 
order by b asc) def

Thanks in advance

Tab Alleman <talleman at Lumpsum.com> wrote: But pursuing Rudy's idea, you could make an ordering column that uses the DATEDIFF and its inverse.  But he's probably right; whatever you're trying to do might better be done without a UNION at all.

> -----Original Message-----
> From: thelist-bounces at lists.evolt.org
> [mailto:thelist-bounces at lists.evolt.org]On Behalf Of r937
> Sent: Thursday, October 18, 2007 2:30 PM
> To: thelist at lists.evolt.org
> Subject: [thelist] SQL Union and order by problem
> 
> 
> >  you could have a column with the value -b in the first SELECT...
> 
> uh, wait a sec...   b appears to be a date
> 
> i would suggest you take another look, or explain what you're 
> doing, because 
> right now i don't think you need a UNION at all
> 
> ;o)
> 
> 
> -- 
> 
> * * Please support the community that supports you.  * *
> http://evolt.org/help_support_evolt/
> 
> For unsubscribe and other options, including the Tip Harvester 
> and archives of thelist go to: http://lists.evolt.org 
> Workers of the Web, evolt ! 
> 
-- 

* * Please support the community that supports you.  * *
http://evolt.org/help_support_evolt/

For unsubscribe and other options, including the Tip Harvester 
and archives of thelist go to: http://lists.evolt.org 
Workers of the Web, evolt ! 


 __________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


More information about the thelist mailing list