When you use aggregate functions (such as Max) each column named in the
SELECT clause must be part of an aggregate function or a GROUP BY clause.
Notice in my original example that CustomerID appears in the GROUP BY
clause
as well as in the SELECT clause - the example displays each customer ID
along with the date of the most recent order by that customer.
Sometimes (not always, but sometimes) it might be necessary to use two or
more queries to bring together the information you want. For example, if
I
wanted to include additional information about a customer, I might use
the
query in my original example and then join that query to the customers
table
on the CustomerID column to bring in columns from the customer table.
--
Brendan Reynolds (MVP)
ktm400 said:
Thank you.... another question:
This works
SELECT Max([Press 2]!Time) AS [Time]
FROM [Press 2]
WHERE ((([Press 2]![BlankID])=1301));
But this does not
SELECT Max([Press 2]!Time) AS [Time], [Press 2].BlankID, [Press
2].ProgramNo
FROM [Press 2]
WHERE ((([Press 2]![BlankID])=1301));
Why can't I show the additional columns?
:
Here's an example using the Orders table from the SQL Server version
of
Northwind ...
SELECT db

rders.CustomerID, Max(db

rders.OrderDate) AS
MaxOfOrderDate
FROM db

rders
GROUP BY db

rders.CustomerID
ORDER BY db

rders.CustomerID;
--
Brendan Reynolds (MVP)
I have a SQL table Iam selecting items from (obdc linked) and I want
to
only
show 1 record of a group. The one I want has the latest date..
How would I query to get this?
Thanks for any help