Dave Punky
Board Regular
- Joined
- Jan 7, 2010
- Messages
- 133
Hi all,
I'm trying to do something that I think should be simple but seems to be presenting more issues than I anticipated.
Basically I have two tables, which look a bit like so:
Table A
[TABLE="class: grid, width: 200"]
<tbody>[TR]
[TD]ID[/TD]
[TD]Title[/TD]
[TD]Type[/TD]
[TD]Table[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]A[/TD]
[TD]A1[/TD]
[TD]Table A[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]B[/TD]
[TD]A2[/TD]
[TD]Table A[/TD]
[/TR]
</tbody>[/TABLE]
Table B
[TABLE="class: grid, width: 200"]
<tbody>[TR]
[TD]ID[/TD]
[TD]Searched ID[/TD]
[TD]Result[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]1[/TD]
[TD]10[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]1[/TD]
[TD]10[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]2[/TD]
[TD]10[/TD]
[/TR]
</tbody>[/TABLE]
I've been trying to write a query that sums the results of Table B and groups by the Searched ID basically creates a recordset which would look like so with the information above:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]ID[/TD]
[TD]Title[/TD]
[TD]Type[/TD]
[TD]Table[/TD]
[TD]Result[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]A[/TD]
[TD]A1[/TD]
[TD]Table A[/TD]
[TD]20[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]B[/TD]
[TD]A2[/TD]
[TD]Table A[/TD]
[TD]10[/TD]
[/TR]
</tbody>[/TABLE]
My current SQL query is like so:
I've got this working over a union query for multiple tables, however when trying to just look at these two tables Access is expecting an operator for [Result] that I can't seem to account for. I'm actually sending the query via VBA from Excel so it just errors advising it doesn't have the minimum parameters.
I'm almost certain I'm doing something obviously wrong but I can't seem to quite work it out - any advice on what I've done wrong in my query above? I've tried doing a left join as well from Table A to B but I'm having issues grouping the ID's together in Table B to subsequently attach them to the initial table.
I'm trying to do something that I think should be simple but seems to be presenting more issues than I anticipated.
Basically I have two tables, which look a bit like so:
Table A
[TABLE="class: grid, width: 200"]
<tbody>[TR]
[TD]ID[/TD]
[TD]Title[/TD]
[TD]Type[/TD]
[TD]Table[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]A[/TD]
[TD]A1[/TD]
[TD]Table A[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]B[/TD]
[TD]A2[/TD]
[TD]Table A[/TD]
[/TR]
</tbody>[/TABLE]
Table B
[TABLE="class: grid, width: 200"]
<tbody>[TR]
[TD]ID[/TD]
[TD]Searched ID[/TD]
[TD]Result[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]1[/TD]
[TD]10[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]1[/TD]
[TD]10[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]2[/TD]
[TD]10[/TD]
[/TR]
</tbody>[/TABLE]
I've been trying to write a query that sums the results of Table B and groups by the Searched ID basically creates a recordset which would look like so with the information above:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]ID[/TD]
[TD]Title[/TD]
[TD]Type[/TD]
[TD]Table[/TD]
[TD]Result[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]A[/TD]
[TD]A1[/TD]
[TD]Table A[/TD]
[TD]20[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]B[/TD]
[TD]A2[/TD]
[TD]Table A[/TD]
[TD]10[/TD]
[/TR]
</tbody>[/TABLE]
My current SQL query is like so:
Code:
SELECT [ID], [Title], [Type], [Table], (SELECT Sum([Table B.Result]) AS sum FROM Table B WHERE [Table A.ID]=[Table B.Searched ID]) AS [Result]
FROM Table A
WHERE [Title] LIKE "*A*"
ORDER BY [Result] DESC, [Title] ASC;
I've got this working over a union query for multiple tables, however when trying to just look at these two tables Access is expecting an operator for [Result] that I can't seem to account for. I'm actually sending the query via VBA from Excel so it just errors advising it doesn't have the minimum parameters.
I'm almost certain I'm doing something obviously wrong but I can't seem to quite work it out - any advice on what I've done wrong in my query above? I've tried doing a left join as well from Table A to B but I'm having issues grouping the ID's together in Table B to subsequently attach them to the initial table.