Thank's for your reply. I didnt realize this, but of course it is logical.
So, now I think how to select not only one row (what seems to be easy) but set of rows from previously mentioned data where only these rows are picked up with largest Data value for each IdMat, so correct version of querry:
SELECT Mieszalnia.IdMat, Mieszalnia.Partia, Mieszalnia.Kont,
Mieszalnia.Uk, Max(Mieszalnia.Data) FROM Mieszalnia GROUPED BY Mieszalnia.IdMat;

IdW  IdMat  Partia      Kont         Uk      Data
12   1      1179760     136832     F16     1171951258
12   2      1176865     315060     F21     1171915832
13   3      1177504     318272     F9      1171538132
15   4      1153571     277827     F15     1171437632
16   5      1153437     062022     F16     1171368032
17   6      1185543     323063     SL1     1171978232
18   7      1156166     077690     F3      1169082032
19   8      1156269     075825     F8      1168888832
20   9      1166581     101109     F11     1168014032
21   10     1099211     081868     F17     1166497232
22   11     1084774     054445     F20     1169530232
23   12     1143641     157155     F24     1171485032
24   13     1180275     179329     SF3     1169521232
25   14     1102698     150010     SF4     1171494000
26   15     1130267     266647     SF5     1170282600
27   6      111111      111111     sl1     1172135769
28   6      33333       33333      sl1     1172054927



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]
-----------------------------------------------------------------------------




--
Używam klienta poczty Opera Mail: http://www.opera.com/mail/

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

Reply via email to