Re: [SQL] Random sort with distinct

2010-10-04 Thread Ozer, Pam
What about dynamic queries?

 

From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] On 
Behalf Of Dmitriy Igrishin
Sent: Saturday, October 02, 2010 6:40 AM
To: Ozer, Pam
Cc: pgsql-sql@postgresql.org
Subject: Re: [SQL] Random sort with distinct

 

Hey Ozer,

How about dynamic queries?

2010/10/2 Ozer, Pam 

I have the following query

 

Select Distinct VehicleMake, VehicleModel

From VehicleYearMakeModelTrim

Order by random()

Limit 10;

 

I don’t want to bring back the random number I just want the sort order to be 
random. How can I sort randomly?  This query breaks because random() is not in 
the select.

 

Thanks

 

Pam

 




-- 
// Dmitriy.





Re: [SQL] join returns too many results...

2010-10-04 Thread Joshua Tolley
On Sun, Oct 03, 2010 at 02:54:41PM -0400, Frank Bax wrote:
> Whatever clause I choose to add I *must* ensure that final result set  
> contains only one-to-one join between tables.  Either of these two  
> results is acceptable:
>
> For option 1; result C=All or C=Centre is acceptable.
> For option 2; result B=NE70 or B=NE75 or B=NE80 is acceptable.
>
> I am lost trying to construct SQL to accomplish this...

Try DISTINCT ON, after ensuring the results are ordered meaningfully.

http://www.postgresql.org/docs/current/interactive/sql-select.html#SQL-DISTINCT

--
Joshua Tolley / eggyknap
End Point Corporation
http://www.endpoint.com


signature.asc
Description: Digital signature