Search Postgresql Archives

Re: Is it possible to make the order of output the same as the order of input parameters?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



* m. hvostinski (makhvost@xxxxxxxxx) wrote:
> I have a simple query like:
> 
> SELECT * FROM customer WHERE id IN (23, 56, 2, 12, 10)
> 
> The problem is that I need to retrieve the rows in the same order as the set
> of ids provided in the select statement. Can it be done?

Not very easily.  My first thought would be doing something like:

SELECT
  customer.*
FROM
  customer a
  JOIN (VALUES (1,23),(2,56),(3,2),(4,12),(5,10)) b
    ON (a.id = b.column2)
ORDER BY b.column1
;

	Thanks,

		Stephen

Attachment: signature.asc
Description: Digital signature


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux