Question: 1-I want to execute this query : -- The most expensive item sold ever SELECT c.itemID, c.itemName FROM item AS c JOIN ( SELECT b.itemID

1-I want to execute this query :

-- The most expensive item sold ever SELECT c.itemID, c.itemName FROM item AS c JOIN ( SELECT b.itemID as 'itemid', MAX(b.item_initialPrice) AS 'MaxPrice' FROM buyeritem AS a INNER JOIN item AS b ON a.item_ID = b.itemID ) as d ON c.itemID = d.itemid group by c.itemID, c.itemName; 

my item table looks like that:

create table item ( itemID int IDENTITY(1000,1) NOT NULL, itemName varchar(15) NOT NULL, Item_desc varchar(255), Item_initialPrice MONEY, ItemQty int, ownerID int NOT NULL, condition varchar(20) NOT NULL, PRIMARY KEY (itemID), FOREIGN KEY (ownerID) references seller (sellerID)); 

seller table:

create table seller ( sellerID INT IDENTITY(1000,1) NOT NULL, sellerName varchar(20) NOT NULL, sellerUserName varchar(20) UNIQUE, sellerPassword varchar(32) NOT NULL,

item_ID int NOT NULL, contact_ID int NOT NULL, creditCardID int NOT NULL, primary key(sellerID),

Foreign Key(contact_ID) references contactInfo(contactID), Foreign Key(creditCardID) references creditCardInfo(credit_CardID));

buyerItem table

create table buyerItem ( buyer_ID int NOT NULL, item_ID int NOT NULL, PRIMARY KEY(buyer_ID,item_ID),

FOREIGN KEY (buyer_ID) REFERENCES buyer(buyerID), FOREIGN KEY (item_ID) REFERENCES item(itemID));

SO the problem is that I have Column 'item.itemID' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause. i tried to add a group by clause at the end group by c.itemID, c.itemName, but its the same error? dont really know where the problem comes from??

2- I also have this query

-- The most active seller(the one who has offered the most number of items) SELECT a.ownerID, b.sellerName FROM item AS a INNER JOIN seller AS b ON a.ownerID = b.sellerID GROUP BY a.ownerID,b.sellerName ORDER BY COUNT(a.itemID) DESC; 

I want to add itemQty along with the ownerID and sellerName from item table stated above, what would be the best way to achieve that?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!