0% found this document useful (0 votes)
4 views

SQL Commands Questions for BAIT_2

The document contains SQL command questions and answers related to two sample tables: SUPPLIER and MANUFACTURER. It includes various queries for retrieving, updating, and deleting data, as well as aggregating information from these tables. The document serves as a reference for SQL operations involving supplier and manufacturer data.

Uploaded by

libabaidrisa84
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

SQL Commands Questions for BAIT_2

The document contains SQL command questions and answers related to two sample tables: SUPPLIER and MANUFACTURER. It includes various queries for retrieving, updating, and deleting data, as well as aggregating information from these tables. The document serves as a reference for SQL operations involving supplier and manufacturer data.

Uploaded by

libabaidrisa84
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

SQL command questions and answers involving two

sample tables: SUPPLIER and MANUFACTURER.

Tables Schema:

1. SUPPLIER
o supplier_id (INT)
o supplier_name (VARCHAR)
o city (VARCHAR)
o country (VARCHAR)
o contact_name (VARCHAR)
o phone (VARCHAR)
o email (VARCHAR)
o supply_date (DATE)

2. MANUFACTURER
o manufacturer_id (INT)
o manufacturer_name (VARCHAR)
o city (VARCHAR)
o country (VARCHAR)
o contact_name (VARCHAR)
o phone (VARCHAR)
o email (VARCHAR)
o product_type (VARCHAR)

Questions and Answers

1. Q: Retrieve all columns from the SUPPLIER table.

A: SELECT * FROM SUPPLIER;

2. Q: Select only supplier_name and city from the SUPPLIER table.

A: SELECT supplier_name, city FROM SUPPLIER;

3. Q: Find all suppliers from the country 'USA'.

A: SELECT * FROM SUPPLIER WHERE country = 'USA';


4. Q: Retrieve the total number of suppliers.

A: SELECT COUNT(*) FROM SUPPLIER;

5. Q: List all distinct cities where suppliers are located.

A: SELECT DISTINCT city FROM SUPPLIER;

6. Q: Get supplier names in alphabetical order.

A: SELECT supplier_name FROM SUPPLIER ORDER BY supplier_name ASC;

7. Q: Find suppliers who have 'John' in their contact name.

A: SELECT * FROM SUPPLIER WHERE contact_name LIKE '%John%';

8. Q: Count the number of manufacturers in 'Germany'.

A: SELECT COUNT(*) FROM MANUFACTURER WHERE country = 'Germany';

9. Q: Retrieve all manufacturers producing 'Electronics'.

A: SELECT * FROM MANUFACTURER WHERE product_type = 'Electronics';

10. Q: List manufacturer names and product types.

A: SELECT manufacturer_name, product_type FROM MANUFACTURER;

11. Q: Retrieve the suppliers who supplied products before '2023-01-01'.

A: SELECT * FROM SUPPLIER WHERE supply_date < '2023-01-01';

12. Q: Find the maximum supply date in the SUPPLIER table.

A: SELECT MAX(supply_date) FROM SUPPLIER;

13. Q: Retrieve the manufacturer details from 'Paris'.

A: SELECT * FROM MANUFACTURER WHERE city = 'Paris';

14. Q: List manufacturers ordered by manufacturer_name descending.

A: SELECT * FROM MANUFACTURER ORDER BY manufacturer_name DESC;

15. Q: Get the number of suppliers for each country.


A: SELECT country, COUNT(*) FROM SUPPLIER GROUP BY country;

16. Q: Find suppliers with no email provided.

A: SELECT * FROM SUPPLIER WHERE email IS NULL;

17. Q: Update the phone of a supplier with supplier_id 101 to '1234567890'.

A: UPDATE SUPPLIER SET phone = '1234567890' WHERE supplier_id = 101;

18. Q: Delete manufacturers from 'India'.

A: DELETE FROM MANUFACTURER WHERE country = 'India';

19. Q: Insert a new supplier into the SUPPLIER table.

A:

INSERT INTO SUPPLIER (supplier_id, supplier_name, city, country,


contact_name, phone, email, supply_date)

VALUES (201, 'New Supplier', 'Tokyo', 'Japan', 'Kenji Tanaka',


'9876543210', '[email protected]', '2025-01-15');

20. Q: Find all manufacturers who have their names starting with 'S'.

A: SELECT * FROM MANUFACTURER WHERE manufacturer_name LIKE 'S%';

21. Q: Retrieve the first five suppliers sorted by supply_date.

A: SELECT * FROM SUPPLIER ORDER BY supply_date ASC LIMIT 5;

22. Q: Find the average number of suppliers per city.

A: SELECT AVG(supplier_count) FROM (SELECT city, COUNT(*) AS


supplier_count FROM SUPPLIER GROUP BY city) AS city_counts;

23. Q: List all suppliers who have supplied after '2024-01-01' and are from 'Canada'.

A: SELECT * FROM SUPPLIER WHERE supply_date > '2024-01-01' AND country =


'Canada';

24. Q: Get the email and phone of manufacturers producing 'Furniture'.

A: SELECT email, phone FROM MANUFACTURER WHERE product_type =


'Furniture';
25. Q: Find the supplier names along with the count of supplies they have made.

A: SELECT supplier_name, COUNT(supply_date) FROM SUPPLIER GROUP BY


supplier_name;

26. Q: Retrieve all manufacturers from the same city as suppliers.

A:

SELECT m.* FROM MANUFACTURER m

INNER JOIN SUPPLIER s ON m.city = s.city;

27. Q: Find suppliers whose supplier_id is either 102 or 103.

A: SELECT * FROM SUPPLIER WHERE supplier_id IN (102, 103);

28. Q: Select suppliers with a supply_date between '2023-01-01' and '2024-01-01'.

A: SELECT * FROM SUPPLIER WHERE supply_date BETWEEN '2023-01-01' AND


'2024-01-01';

29. Q: Get all manufacturers who do not have a contact name.

A: SELECT * FROM MANUFACTURER WHERE contact_name IS NULL;

30. Q: Count the number of unique product types in the MANUFACTURER table.

A: SELECT COUNT(DISTINCT product_type) FROM MANUFACTURER;

31. Q: Retrieve suppliers from countries not listed as 'USA' or 'UK'.

A: SELECT * FROM SUPPLIER WHERE country NOT IN ('USA', 'UK');

32. Q: Update the email of the manufacturer with manufacturer_id 301 to


'[email protected]'.

A: UPDATE MANUFACTURER SET email = '[email protected]' WHERE


manufacturer_id = 301;

33. Q: Delete suppliers with no phone number.

A: DELETE FROM SUPPLIER WHERE phone IS NULL;

34. Q: Find the top three cities with the most suppliers.

A:
SELECT city, COUNT(*) as supplier_count
FROM SUPPLIER
GROUP BY city
ORDER BY supplier_count DESC
LIMIT 3;

35. Q: List manufacturers who have a name containing 'Tech'.

A: SELECT * FROM MANUFACTURER WHERE manufacturer_name LIKE '%Tech%';

36. Q: Retrieve all suppliers and their corresponding manufacturer details for matching
cities.

A:

SELECT s.*, m.*


FROM SUPPLIER s
INNER JOIN MANUFACTURER m ON s.city = m.city;

37. Q: Find the sum of all suppliers grouped by country.

A: SELECT country, COUNT(*) FROM SUPPLIER GROUP BY country;

38. Q: List manufacturers who are not located in 'New York'.

A: SELECT * FROM MANUFACTURER WHERE city <> 'New York';

39. Q: Get all suppliers whose name ends with 'Corp'.

A: SELECT * FROM SUPPLIER WHERE supplier_name LIKE '%Corp';

40. Q: Retrieve the manufacturer names and count of product types they produce.

A: SELECT manufacturer_name, COUNT(product_type) FROM MANUFACTURER GROUP


BY manufacturer_name;

You might also like