Re: Need help Regarding executing select query
Lew wrote:
Ed Webb wrote:
Lew wrote:
Pradeep wrote:
I have one problem in getting Results using select Query...
Query:
------------ -
Select product_sys_ id,product_ name from Product where product_sys_
id in(9,6,4,1,2) ;
Besides, the question isn't how to achieve a particular order, but how
to match the order emitted by the RDBMS. The OP isn't asking how to
impose the random-seeming order, AFAICT, but suspects that the Java
system is somehow altering the order as returned by the RDBMS. I doubt
that this is the case. I suspect that some part of the application is
ordering the data. I've been wrong about that sort of thing before, of
course. There isn't enough information on the board yet to do more than
speculate.
Oy, now I see it. They want to order the result by the order of the items in
the IN clause. Oy, gevalt.
Not without a function to re-order based on the IN clause order, and that's a
hack. Really, the best advice is: Don't.
It's hard for me to imagine a business case for coercing a SELECT ... WHERE
.... IN clause to match the output order. Ordering is for result sets, not
query clauses.
Note that the SQL statement has the exact same meaning no matter what order
the IN set has. It would be a violation of SQL semantics for that to make a
difference.
So, OP, figure out an order that makes sense for your result set. Make sure
there's a column or function that you can include in the column set and use
for ORDER BY. Under no circumstances craft a WHERE ... IN set wherein you
think order of the set matters, because it doesn't.
--
Lew