Thread:
<div class="Section1"><p class="MsoNormal">Hello Everyone,<p class="MsoNormal"> <p class="MsoNormal"> I havea array of ids from my search result and now I want to fetch the details from the database.<p class="MsoNormal">Now INquery is ruined my sort order.So should I go for Union All?<p class="MsoNormal">Is there any other method to fetch thedata..?<p class="MsoNormal"> <p class="MsoNormal">Please help me in this….<p class="MsoNormal">Thanks in advance…<p class="MsoNormal"> <pclass="MsoNormal">With Regards,<p class="MsoNormal">Hemant Patel<p class="MsoNormal"> </div><br /><hr/><font color="Gray" face="Arial" size="1">NOTE: This message may contain information that is confidential, proprietary,privileged or otherwise protected by law. The message is intended solely for the named addressee. If receivedin error, please destroy and notify the sender. Any use of this email is prohibited when received in error. Impetusdoes not represent, warrant and/or guarantee, that the integrity of this communication has been maintained nor thatthe communication is free of errors, virus, interception or interference.<br /><br /> Impetus is the winner of the EconomicTimes Intel Smart Workplace Awards 2008 and the CNBC emerging India 2008. Visit www.impetus.com for details.<br /></font>
Hello Everyone,I have a array of ids from my search result and now I want to fetch the details from the database.Now IN query is ruined my sort order.So should I go for Union All?
Is there any other method to fetch the data..?
Please help me in this….Thanks in advance…With Regards,Hemant Patel
Let Say I have the array of primary key of some table say XYZ.
For e.g. (555,222,333,111)
When I query for these results I will get the result like in the order of (111,222,333,555) .
So now I need to process in the business logic to maintain the search criteria.
But I want the result from IIN query… the order I provide the ids
And if I will make query like ,
select * from XYZ where id=555 UNION ALL select * from XYZ where id=222 etc
Then it will return in that order.
so which one is better approach,
Or is there any other way…?
With Regards,
Hemant Patel
From: ries van Twisk [mailto:pg@rvt.dds.nl]
Sent: Wednesday, November 05, 2008 8:21 PM
To: Hemant Patel
Cc: pgsql-sql
Subject: Re: [SQL]
On Nov 5, 2008, at 8:42 AM, Hemant Patel wrote:
Hello Everyone,
I have a array of ids from my search result and now I want to fetch the details from the database.
Now IN query is ruined my sort order.So should I go for Union All?
IN doesn't ruin your sort order really.... You need to think in sets...
Is there any other method to fetch the data..?
Can't you not directly join against you other table to fetch the result directly??
Show us the SQL you are working with + tables would help aswell.
Please help me in this….
Thanks in advance…
With Regards,
Hemant Patel
NOTE: This message may contain information that is confidential, proprietary, privileged or otherwise protected by law. The message is intended solely for the named addressee. If received in error, please destroy and notify the sender. Any use of this email is prohibited when received in error. Impetus does not represent, warrant and/or guarantee, that the integrity of this communication has been maintained nor that the communication is free of errors, virus, interception or interference.
Impetus is the winner of the Economic Times Intel Smart Workplace Awards 2008 and the CNBC emerging India 2008. Visit www.impetus.com for details.
On Wed, Nov 5, 2008 at 9:21 AM, Hemant Patel <hemant.patel@impetus.co.in> wrote: > Let Say I have the array of primary key of some table say XYZ. > > For e.g. (555,222,333,111) > > > > When I query for these results I will get the result like in the order of > (111,222,333,555) . > > So now I need to process in the business logic to maintain the search > criteria. The fact that you get results in a certain order without using an order by clause is a happy coincidence, and not to be relied upon. Should PostgreSQL choose a different query plan they may come back in some other order. I.e. you HAVE to use an order by clause if you want a certain order. period.