Home > Mobile >  How to select data in 2 different table with ACCESS
How to select data in 2 different table with ACCESS

Time:10-26

Im trying to SELECT Data from 2 Different Table.

Below are the 2 Table

Table1
Date       Name   Value1 Value2
25/10/2021 Name1  1      7
25/10/2021 Name2  3      8
25/10/2021 Name3  5      9
25/10/2021 Name1  1      3

Table2
Date       Name    Class
25/10/2021 Name1   A
25/10/2021 Name2   B
25/10/2021 Name3   A

The wanted output is :

Name   Value1 Value2  Class
Name1  2      10      A
Name2  3      8       B
Name3  5      9       A

I tried the following query but It throw an error

Your query does not include the specified expression 'Class' as part of an aggregate function

SELECT Table2.Class, Sum(Table1.Value1), Sum(Table1.Value2)
FROM Table1
INNER JOIN Table2 ON Table1.Name = Table2.Name
WHERE Table1.Date = #25/10/2021#
ORDER BY Table1.Name

CodePudding user response:

You miss to group by Class:

SELECT Table2.Class, Sum(Table1.Value1), Sum(Table1.Value2)
FROM Table1
INNER JOIN Table2 ON Table1.Name = Table2.Name
WHERE Table1.Date = #25/10/2021#
GROUP BY Table2.Class
ORDER BY Table1.Name
  • Related