J
JonWayn
When used in an append query, does the 'Order By' clause affect the order in
which records are appended?
which records are appended?
JonWayn said:When used in an append query, does the 'Order By' clause affect the order in
which records are appended?
Stephen K. Young said:Actually, I believe Access does honor the Order By criteria in an insert
query.
This is useful if you have multiple source records with the same key field,
and you want to give a preference to some records over a other records,
based on a non-key field sort order.
- Steve
order
Stephen K. Young said:I once had occasion to use an Order By criteria in an Insert query to import
thousands of records from an external source. The external data was mostly
ok, but it did not have an enforced key field, so naturally there were
duplicate records, some with missing data or bad data.
To import this, I could have made a Group By query on the key field and
inserted the max of the data, or skipped nulls, or performed various other
manipulations. But I wanted to get complete records, not a mix of values
from different duplicate records, and it would have taken several queries in
sequence to select the proper records. Instead, I simply sorted by the
preference criteria for acceptance, using a single Insert query into a keyed
table. This way, the query inserted individual records without mixing data
between records, but the preferred records were inserted first, and
remaining records were rejected as key violations. The important thing is
that the preferred records were inserted first in order to reject the
remaining records.
If desired, I could then have a separate query to display the duplicate
records.
I would consider this an implementation trick that works with Jet. I don't
know what the ANSI SQL standard says about Order By criteria on an Insert
query.
A Top query would not work for this, because I needed to perform sorting and
selecting grouped for each key field value, whereas a Top query orders and
subsets the entire table at once.
- Steve
Marshall Barton said:Interesting, Sky. I suppose that could be useful along with
a TOP predicate. Do you have an example of another way to
take advantage of this capability?
I don't think this has anything to do with "affect the order
in which records are appended", or am I missing the point?
--
Marsh
MVP [MS Access]
Stephen K. Young said:Actually, I believe Access does honor the Order By criteria in an insert
query.
This is useful if you have multiple source records with the same key field,
and you want to give a preference to some records over a other records,
based on a non-key field sort order.
- Steve
JonWayn wrote:
When used in an append query, does the 'Order By' clause
affect the order in which records are appended?
Marshall Barton said:Interesting, Sky. I suppose that could be useful along with
a TOP predicate. Do you have an example of another way to
take advantage of this capability?
I don't think this has anything to do with "affect the order
in which records are appended", or am I missing the point?
--
Marsh
MVP [MS Access]
Stephen K. Young said:Actually, I believe Access does honor the Order By criteria in an insert
query.
This is useful if you have multiple source records with the same key field,
and you want to give a preference to some records over a other records,
based on a non-key field sort order.
- Steve
Stephen K. Young said:I once had occasion to use an Order By criteria in an Insert query to import
thousands of records from an external source. The external data was mostly
ok, but it did not have an enforced key field, so naturally there were
duplicate records, some with missing data or bad data.
To import this, I could have made a Group By query on the key field and
inserted the max of the data, or skipped nulls, or performed various other
manipulations. But I wanted to get complete records, not a mix of values
from different duplicate records, and it would have taken several queries in
sequence to select the proper records. Instead, I simply sorted by the
preference criteria for acceptance, using a single Insert query into a keyed
table. This way, the query inserted individual records without mixing data
between records, but the preferred records were inserted first, and
remaining records were rejected as key violations. The important thing is
that the preferred records were inserted first in order to reject the
remaining records.
If desired, I could then have a separate query to display the duplicate
records.
I would consider this an implementation trick that works with Jet. I don't
know what the ANSI SQL standard says about Order By criteria on an Insert
query.
A Top query would not work for this, because I needed to perform sorting and
selecting grouped for each key field value, whereas a Top query orders and
subsets the entire table at once.
- Steve
Marshall Barton said:Interesting, Sky. I suppose that could be useful along with
a TOP predicate. Do you have an example of another way to
take advantage of this capability?
I don't think this has anything to do with "affect the order
in which records are appended", or am I missing the point?
--
Marsh
MVP [MS Access]
Stephen K. Young said:Actually, I believe Access does honor the Order By criteria in an insert
query.
This is useful if you have multiple source records with the same key field,
and you want to give a preference to some records over a other records,
based on a non-key field sort order.
- Steve
JonWayn wrote:
When used in an append query, does the 'Order By' clause
affect the order in which records are appended?