woj <[EMAIL PROTECTED]> wrote:
Now, when I run a query:
SELECT Mieszalnia.IdMat, Mieszalnia.Partia, Mieszalnia.Kont,
Mieszalnia.Uk, Max(Mieszalnia.Data) FROM Mieszalnia;
I always get:
IdMat   Partia  Kont    Uk      Data
6 33333 33333 sl1 1172135769

In this result there is indeed max from Data field but rest of the
fields fit not...

When a SELECT statement involves aggregate functions, all column references in the SELECT must be either parameters to some aggregate functions, or else be also mentioned in GROUP BY clause. SQLite allows, as an extension, departure from this rule, but the row from which values for columns that are neither aggregated nor grouped by are taken is random and unpredictable.

Specifically, in the query you show, there's no guarantee that values for IdMat, Partia and so on would be taken from the same row from which Max(Data) comes. Even if SQLite really wanted to help you out here, it is impossible in general. Consider:

SELECT IdMat, Max(Data), Min(Data) from Mieszalnia;

Which value of IdMat would you expect to see in response to such a query? Should it come from the row with the largest value of Data, with the smallest, or some other?


There are many ways to formulate the query you seem to want. E.g.

select IdMat, Data from Mieszalnia
order by Data desc limit 1;

select IdMat, Data from Mieszalnia
where Data = (select max(Data) from Mieszalnia);

Igor Tandetnik

-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to