I need help with #16:
16. List the vendor codes and names
for the vendors whose product prices are greater than $40, using
IN Subqueries.
MySQL Codes:
CREATE DATABASE DB_M7;
USE DB_M7;
CREATE TABLE VENDOR (
V_CODE
int
NOT NULL,
V_NAME
varchar(30) NOT NULL,
V_CONTACT
varchar(50) NOT NULL,
V_AREACODE char(3)
NOT NULL,
V_PHONE char(8)
NOT NULL,
V_STATE char(2)
NOT NULL,
V_ORDER char(1)
NOT NULL,
CONSTRAINT VENDOR_PK
PRIMARY KEY (V_CODE)
);
CREATE TABLE PRODUCT (
P_CODE
varchar(10) NOT NULL,
P_DESCRIPT
varchar(35) NOT NULL,
P_INDATE date
NOT NULL,
P_QOH
smallint NOT NULL,
P_MIN
smallint NOT NULL,
P_PRICE
decimal(8,2) NOT NULL,
P_DISCOUNT
decimal(5,2) NOT NULL,
V_CODE
int,
CONSTRAINT PRODUCT_PK
PRIMARY KEY (P_CODE),
CONSTRAINT PRODUCT_FK
FOREIGN KEY (V_CODE) REFERENCES
VENDOR(V_CODE)
ON UPDATE CASCADE
ON DELETE NO ACTION
);
INSERT INTO VENDOR VALUES(21225,'Bryson,
Inc.','Smithson','615','223-3234','TN','Y');
INSERT INTO VENDOR VALUES(21226,'SuperLoo,
Inc.','Flushing','904','215-8995','FL','N');
INSERT INTO VENDOR VALUES(21231,'D&E
Supply','Singh','615','228-3245','TN','Y');
INSERT INTO VENDOR VALUES(21344,'Gomez
Bros.','Ortega','615','889-2546','KY','Y');
INSERT INTO VENDOR VALUES(22567,'Dome
Supply','Smith','901','678-1419','GA','Y');
INSERT INTO PRODUCT VALUES('11QER/31','Power painter, 15
psi., 3-nozzle',
'2025-11-3',8,5,109.99,0,22567);
INSERT INTO PRODUCT VALUES('13-Q2/P2','7.25-in. pwr. saw blade',
'2025-12-13',32,15,
14.99,0.05,21344);
INSERT INTO PRODUCT VALUES('14-Q1/L3','9.00-in. pwr. saw blade',
'2025-11-13',18,12,17.49,0,null);
INSERT INTO PRODUCT VALUES('1546-QQ2','Hrd. cloth, 1/4-in., 2x50',
'2026-1-15',15,8,39.95,0,21225);
INSERT INTO PRODUCT VALUES('1558-QW1','Hrd. cloth, 1/2-in., 3x50',
'2026-1-15',23,5,43.99,0,21225);
INSERT INTO PRODUCT VALUES('WR3/TT3','Steel matting, 4''x8''x1/6",
.5" mesh','2026-01-17',18,5,119.95,0.1,21231);
INSERT INTO VENDOR VALUES(11111, 'STUDENT, 'OH', '713',
'221-8000', 'OH', 'Y');
INSERT INTO PRODUCT VALUES('111OH, 'STUDENT', '2026-11-11', 100,
10, 999.99, 0, 11111);
_______________________________________________________________________________
My previous code using IN Subqueries in
#15:
/* Q15 - IN Subqueries */
/* List the product codes, product names, and prices for the
products whose vendor’s area codes are in 615 or 713. */
SELECT P_Code, P_Descript,
P_Price
FROM PRODUCT
WHERE V_Code IN (
SELECT V_Code
FROM VENDOR
WHERE V_Areacode IN
('615','713'));
/* Q15 using Join but same output */
SELECT P_Code, P_Descript,
P_Price
FROM PRODUCT JOIN VENDOR USING
(V_CODE)
WHERE V_Areacode IN
('615','713');
________________________________________
I may have got the answer with:
SELECT VENDOR.V_Code, V_Name, P_Price
FROM PRODUCT JOIN VENDOR USING (V_CODE)
WHERE P_PRICE > 40;
But I don't think it will be right since I was not
using IN Subqueries.
Please help and thank you!
I need help with #16: 16. List the vendor codes and names for the vendors whose product prices are greater than $40, usi
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
I need help with #16: 16. List the vendor codes and names for the vendors whose product prices are greater than $40, usi
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!