Kevin Taylor Kevin Taylor - 6 months ago 8
SQL Question

How to find the sum of a column generated from a query

So, I'm im doing a ticket style database and i'm trying to find the sum of the tickets generated from this. I have attached my query below and the result of it

QUERY RESULT

SELECT Price, TicketID, Ticket.TicketType
FROM Price, Ticket
WHERE Price.TicketType = Ticket.TicketType
;


In the picture, I am trying to get a total for all of the prices that you see in there, each ticketID is a new ticket sold. I can click the totals button in access and it puts a total below it, but I need the total done in the query, so I am wondering how I could do this.

Answer

First, learn to use proper join syntax. Commmas in the FROM clause are simply an archaic way to represent a join.

From what you say, you want sum():

SELECT SUM(Price)
FROM Price JOIN
     Ticket
     ON Price.TicketType = Ticket.TicketType;

This may or may not do exactly what you want. It answers the question quite specifically.