I have a table which has a foreign key that links to a primary key in another table. That id has information on it in which I want it to show while having a sum on the information. Is there a way to do it?

To clarify here's a code that I'm attempting:

Select  `First_Name`, `Last_Name`, `Cart_Item`, Sum(`Ammount`) as "Item Amount" from `transx`,  `employee_name` where `Employee`=1 and employee_name.`id` = 1  group by `Cart_Item`;

The Cart_Item links to a table that has the cart item name and the manufacturer (which has the names "Name" and "ManufactureName" respectively). I want to put that name, with the sum for each group (with the item acting as a particular group) in the same query.

Edited by Kirielson: n/a

5 Years
Discussion Span
Last Post by Kirielson

I am assuming you have an EMPLOYEE & CART entity with each of their primary key and attributes, in addition to a link table, e.g. EMPLOYEE_CART with the foreign keys, Employee_ID, Cart_ID and the Sum.

So to store each instance, use the INSERT INTO statement. E.g. INSERT INTO EMPLOYEE_CART VALUES (Employee_ID, Cart_ID, Sum(Amount)).

You can then pull all the information you want to show, like the names and cart information in a SELECT statement via. the relationsional links indicated above.

Hope that helps.


Kind off. The cart's item is in the basket and I'm trying to recall that particular item in the cart when selecting it since the item is in another table.

Edited by Kirielson: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.