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.

Recommended Answers

All 3 Replies

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.

Found out my error and it had to do with my database.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.