Re: How do the records retrieve from data base when using sql statements?



On Jun 19, 4:08 am, "Saml" <none@xxxxxxxxxxxxxxx> wrote:
Use the "order by" clause.  You really have no choice if you want records in
a specific order.

If you don't use it you might be getting the records in the order you want
today but they may not be in the same order next week.  If, for example, the
file size changes significantly the query optimizer may decide to get the
data another way.

In most cases, "order by" it won't hurt performance if you have the correct
logicals built.  And I'd recommend using the SQL against the physical file,
unless you have select/omit criteria in a logical that you want SQL to
honor.

Sam

"AMOS" <am12...@xxxxxxxxx> wrote in message

news:f72ec7d6-585d-45c9-96da-78c3d76e6964@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx



Hello group,

   When I use a simple "READ FILE", the records are retrieved,
according to the file index. If for example the key of the
file(physical/logical) is "item code", the records are retrieved
according to the item code value.

  However, when I use sql statements in order to retrieve records
from the same physical/logical file, they are not allways retrieved
according to the "item code" order.

  Is there a way to "say" in the sql statements, to retrieve the
records according
to the physical/logical key fields order?
I try to avoid  using "order by" in sql statements in order not to
hurt the query performances when reading large files

Thank you in advance,
Amos- Hide quoted text -

- Show quoted text -

On Jun 19, 4:08 am, "Saml" <none@xxxxxxxxxxxxxxx> wrote:
Use the "order by" clause. You really have no choice if you want records in
a specific order.

If you don't use it you might be getting the records in the order you want
today but they may not be in the same order next week. If, for example, the
file size changes significantly the query optimizer may decide to get the
data another way.

In most cases, "order by" it won't hurt performance if you have the correct
logicals built. And I'd recommend using the SQL against the physical file,
unless you have select/omit criteria in a logical that you want SQL to
honor.

Sam

"AMOS" <am12...@xxxxxxxxx> wrote in message

news:f72ec7d6-585d-45c9-96da-78c3d76e6964@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx



Hello group,

When I use a simple "READ FILE", the records are retrieved,
according to the file index. If for example the key of the
file(physical/logical) is "item code", the records are retrieved
according to the item code value.

However, when I use sql statements in order to retrieve records
from the same physical/logical file, they are not allways retrieved
according to the "item code" order.

Is there a way to "say" in the sql statements, to retrieve the
records according
to the physical/logical key fields order?
I try to avoid using "order by" in sql statements in order not to
hurt the query performances when reading large files

Thank you in advance,
Amos- Hide quoted text -

- Show quoted text -

Hello Sam,

Thank you for your guidance.

One thing I would like to understand: Does using sql stattemnts
on the physical file only(not join), ensures retrieving rows according
to the keys order? When I use the "read" instruction in the RPG
program, the records are retrieved exactly according to the key
sequence.

Now if I've to use the "order by" clause on the key fields, what
happens if the file contains a lot of records. Does the query
optimizer decide to use the file key in order to retrieve the records?

my query is simple:
select field1, field2,..
from physicalFile
orfer by keyField

Thank you in advance,
Amos
.



Relevant Pages

  • Re: How do the records retrieve from data base when using sql statements?
    ... file size changes significantly the query optimizer may decide to get the ... unless you have select/omit criteria in a logical that you want SQL to ... on the physical file only, ensures retrieving rows according ...
    (comp.sys.ibm.as400.misc)
  • Re: How do the records retrieve from data base when using sql statements?
    ... The query optimizer is a complicated beast. ... SQL over a physical file that is keyed by your selection criteria, ...
    (comp.sys.ibm.as400.misc)
  • RE: SQL Server Login
    ... You can copy the SQL ... statements from you old query to a new query. ... Create new query selecting the database file on new server. ... How can I change the source of the data so it is retrieving the data from ...
    (microsoft.public.excel.misc)
  • SQL Query Question (Access)
    ... First I am executing a query that returns the most recent model that is ... Location - NewestModel ... I am able to get those results with no problem using the following SQL ... above but instead of the MAX NewestModel it is retrieving all of them. ...
    (microsoft.public.dotnet.framework.adonet)
  • SQL Query Question (Access)
    ... First I am executing a query that returns the most recent model that is ... Location - NewestModel ... I am able to get those results with no problem using the following SQL ... above but instead of the MAX NewestModel it is retrieving all of them. ...
    (microsoft.public.dotnet.framework.adonet)

Loading