J
Jesse
I am trying to figure out the function of "FIRST" in a totals query -
with little luck so far. I think that my intuition may be getting in
the way.
Using Access 2000. I have an orders detail table (tbl_orders_d) with
the usual stuff -- trans_num, product_name, quantity, price, and a
unique auto_num field. I want to do a query that yields just 1 row
for each order (whether there is only 1 record or 5) -- so, I created
a totals query (qry_1) for tbl_orders_d. I dragged each column to the
query grid and on the Total line in the grid cell for trans_num I
applied "FIRST". (First or Last, for this problem, it doesn't
matter.) I figured - incorrectly - that this would leave me with only
the first row showing for each order_num. Instead, every row was
displayed for each order_num.
By trial and error ... The only approach that has worked for me in
qry_1 is to select ONLY the trans_num and auto_num fields from
tbl_order_d and apply FIRST to auto_num. (Since each auto_num is
unique, I have no idea why this works. Kinda like 1000 monkeys and 1
somehow types something meaningful.) Also, I have to NOT select any
other columns - otherwise, every row for every order is displayed.
Instead (since I don't know how to do sub-queries, which is fine for
now) I then created qry_2 that combines qry_1 with tbl_orders to add
back (so to speak) the product_name, quantity, and price columns --
but still only showing the first row for each order. So, success of
sorts.
And yet, my questions are:
1. What is FIRST supposed to do -- and why is it working when applied
to the unique auto-num field?
2. Is there a way to include the product_name, quantity, and price
fields in qry_1 and still have that query work - that is, so that only
1 row/order is displayed? In other words, I would like to have these 3
columns display in the results but they should not affect what rows
are displayed.
Thanks. -- Jesse
with little luck so far. I think that my intuition may be getting in
the way.
Using Access 2000. I have an orders detail table (tbl_orders_d) with
the usual stuff -- trans_num, product_name, quantity, price, and a
unique auto_num field. I want to do a query that yields just 1 row
for each order (whether there is only 1 record or 5) -- so, I created
a totals query (qry_1) for tbl_orders_d. I dragged each column to the
query grid and on the Total line in the grid cell for trans_num I
applied "FIRST". (First or Last, for this problem, it doesn't
matter.) I figured - incorrectly - that this would leave me with only
the first row showing for each order_num. Instead, every row was
displayed for each order_num.
By trial and error ... The only approach that has worked for me in
qry_1 is to select ONLY the trans_num and auto_num fields from
tbl_order_d and apply FIRST to auto_num. (Since each auto_num is
unique, I have no idea why this works. Kinda like 1000 monkeys and 1
somehow types something meaningful.) Also, I have to NOT select any
other columns - otherwise, every row for every order is displayed.
Instead (since I don't know how to do sub-queries, which is fine for
now) I then created qry_2 that combines qry_1 with tbl_orders to add
back (so to speak) the product_name, quantity, and price columns --
but still only showing the first row for each order. So, success of
sorts.
And yet, my questions are:
1. What is FIRST supposed to do -- and why is it working when applied
to the unique auto-num field?
2. Is there a way to include the product_name, quantity, and price
fields in qry_1 and still have that query work - that is, so that only
1 row/order is displayed? In other words, I would like to have these 3
columns display in the results but they should not affect what rows
are displayed.
Thanks. -- Jesse