Yes. Here's the first sentence from the help topic about the GROUP BY clause:
VFP Help said:
The GROUP BY clause specifies one or more columns used to group rows returned by the query. Columns referenced in the SQL SELECT statement list, except for aggregate expressions, must be included in the GROUP BY clause.
Your GROUP BY clause only specifies grouping by Journaldb.terminal, a single field. That's the only field you may specify in your SELECT field list as an unaggregated value.
Keep in mind, or finally learn, what GROUP BY means: The goal is to have
one and exactly one record per group. The groups are defined by the value or tuple of values the columns have, that you specify in the GROUP BY clause. So, those columns can be interpreted as the head data of a group, data that by definition is the same in all the records of the group before the grouping aggregation, the group by happens.
But that can't be said for any other columns, so depending on your point of view, you have to add them to the GROUP BY clause to make that valid, or you have to remove them from the SELECT field list to make the GROUP BY clause valid.
Nobody can tell you what you want. If you group by all these fields, unless they all are the same value for the same Journaldb.terminal, you get more groups, more specialized groups. In the extreme case of specifying all columns of a record, each record becomes its own group and grouping becomes pointless.
In cases, none of the two alternatives of putting fewer fields in the SELECT field list nor adding more fields to the GROUP BY field list reaches your goal, that type of query is not solving your problem, not in one step.
I see you want summary information of all the journals coming from the same terminal. Well, if there are several types in Journaldb.type_ that's beyond what you can get in one single record per terminal. Also in a SQL query result the type_ column can only store one value. GROUP BY won't list all Journaldb.type_ values for the same Journaldb.terminal.
You need a separate query for that aspect. If you are still interested in the MIN(Journaldb.seq_num), MAX(Journaldb.seq_num), that is the range of sequence numbers of journal rows from the whole terminal and not just from the journal rows of a certain type, this can't be answered in a single query.
Here are the two queries for just these aspects as a starter:
Code:
SELECT Journaldb.terminal, Journaldb.termi_name, MIN(Journaldb.seq_num), MAX(Journaldb.seq_num);
FROM journaldb;
WHERE Journaldb.type_ = "Cash ";
GROUP BY Journaldb.terminal, Journaldb.termi_name;
ORDER BY Journaldb.terminal, Journaldb.termi_name;
INTO CURSOR journalterminalsequencenumberranges
SELECT Journaldb.terminal, Journaldb.termi_name, Journaldb.type_;
FROM journaldb;
WHERE Journaldb.type_ = "Cash ";
GROUP BY Journaldb.terminal, Journaldb.termi_name, Journaldb.type_;
ORDER BY Journaldb.terminal, Journaldb.termi_name, Journaldb.type_;
INTO CURSOR journalterminaltypes
The ranges you get from the first query üer terminal will cover all journal types. You can add MIN(Journaldb.seq_num), MAX(Journaldb.seq_num) to the field list of the second query, but when there are multiple types, only the minimum of all minimum values and the maximum of all maximum values will be the values you get from the first query. The rows for a specific type are obviously a subgroup. And that's the core reason you can't get that, a GROUP BY query is not able to give you nested hierarchical data. It is determined to give you one record per group. Other ways of grouping are partitioning queries and VFP SQL does not cover that.
If the overall journal is feed by all terminals chronologically, these ranges will not really give you the portion of records only about one specific terminal, the ranges can nest and overlap within each other unless each terminal has its own sequence number counter.
Last, not least: In earlier VFP versions you could group that way and the SQL engine would then give you the values of the first row of a group, but that means if you did that in the past you dropped a lot of detail information. Eg you got Journaldb.type_ even when there are multiple ones in all records of the same Journaldb.terminal. VFP9 made this strict and thereby actually fixed a bug of the VFP SQL language. If that code comes from an old project done in previous VFP versions, you've now come to a point to fix something, which likely will bring out really correct data summaries for the first time. So there you have a third vote against solving that by going back to legacy behavior. If it's new code, then anyway, learn how to really use that tool of GROUP BY.
Bye, Olaf.
Olaf Doschke Software Engineering