Re: [SQL] Order by YYYY MM DD in reverse chrono order trouble

2004-04-26 Thread denis
Hi, If you want to SORT descending considering multiple column, you need to spefify DESC after each column. Default is ASC. So, your present sorting is ASC, ASC and DESC You can specify 1 DESC, 2 DESC, 3 DESC HTH Denis - Original Message - From: <[EMAIL PROTECTED]> To: <[EMAIL PROTE

Re: [SQL] Order by YYYY MM DD in reverse chrono order trouble

2004-04-24 Thread Greg Sabino Mullane
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 > I am trying to select distinct dates and order them in the reverse > chronological order. Although the column type is TIMESTAMP, in this > case I want only , MM, and DD back. If you don't need them separated (which I suspect may be the cas

Re: [SQL] Order by YYYY MM DD in reverse chrono order trouble

2004-04-23 Thread ogjunk-pgjedan
Hello, Thank you for all your help, Stijn. date_part is a standard PG function. While not the most elegant, the DESC, DESC, DESC solution suggested the other day works okay for me, so I think I'll use that for now. Thanks again! Otis --- Stijn Vanroye <[EMAIL PROTECTED]> wrote: > Indeed, it seem

Re: [SQL] Order by YYYY MM DD in reverse chrono order trouble

2004-04-23 Thread Stijn Vanroye
Indeed, it seems that I get the same result for a similar query. I'm running version 7.3.4 on a rh 9 server. Also: is the function date_part a function you wrote yourself? I get an error stating that the function date_part("Unknown",date) is not recognized. It maybe not a solution to the actual

Re: [SQL] Order by YYYY MM DD in reverse chrono order trouble

2004-04-22 Thread ogjunk-pgjedan
Hello, Hm, doesn't work for me: [EMAIL PROTECTED] mydb=> select distinct date_part('year', uu.add_date), date_part('month', uu.add_date), date_part('day', uu.add_date) from uus inner join ui on uus.user_id=ui.id inner join uu on ui.id=uu.user_id where uus.subscriber_user_id=1 order by uu.a

Re: [SQL] Order by YYYY MM DD in reverse chrono order trouble

2004-04-22 Thread Tom Lane
<[EMAIL PROTECTED]> writes: > I'd love to be able to do that, but I cannot just ORDER BY uu.add_date, > because I do not have uu.add_date in the SELECT part of the statement. Sure you can. Back around SQL89 there was a restriction that ORDER BY values had to appear in the SELECT list as well, bu

Re: [SQL] Order by YYYY MM DD in reverse chrono order trouble

2004-04-22 Thread Stijn Vanroye
Yes indeed, I seem to have misinterpreted that last one. My apologies. The distinct solution I mentioned isn't going to solve it, you are absolutely right in your example. To get back on track: You don't have to use a field in the select part of you query to be able to use it in the order by cla

Re: [SQL] Order by YYYY MM DD in reverse chrono order trouble

2004-04-22 Thread ogjunk-pgjedan
Hello, I'd love to be able to do that, but I cannot just ORDER BY uu.add_date, because I do not have uu.add_date in the SELECT part of the statement. The reason I don't have it there is because I need distinct MM DD values back. Is there a trick that I could use to make this more elegant? T

Re: [SQL] Order by YYYY MM DD in reverse chrono order trouble

2004-04-21 Thread Edmund Bacon
Is there some reason you can't do this: SELECT DISTINCT date_part('year', uu.add_date), date_part('month', uu.add_date), date_part('day', uu.add_date) FROM uus INNER JOIN ui ON uus.user_id=ui.id INNER JOIN uu ON ui.id=uu.user_id WHERE uus.x_id=1 ORDER BY uu.add_date DESC; This might be

Re: [SQL] Order by YYYY MM DD in reverse chrono order trouble

2004-04-21 Thread ogjunk-pgjedan
Thank you and Denis ([EMAIL PROTECTED]) - that was it. I needed explicit DESC for each ORDER BY criterium. Otis --- Stijn Vanroye <[EMAIL PROTECTED]> wrote: > > Hello, > > > > I am trying to select distinct dates and order them in the reverse > > chronological order. Although the column type i

Re: [SQL] Order by YYYY MM DD in reverse chrono order trouble

2004-04-21 Thread Stijn Vanroye
> Hello, > > I am trying to select distinct dates and order them in the reverse > chronological order. Although the column type is TIMESTAMP, in this > case I want only , MM, and DD back. > > I am using the following query, but it's not returning dates back in > the reverse chronological ord