How to refer the foreign key in correspond table to reference table

in #sql4 months ago

Create table cart_order(
order_id INT,
customer_id INT,
product_id INT,
quantity INT,
order_date DATE,
status VARCHAR(100),
PRIMARY KEY (order_id),
FOREIGN KEY (customer_id) REFERENCES customer(customer_id),
FOREIGN KEY (product_id) REFERENCES product(product_id)
);






-Find out the number of unique countries of the customers in the customer table

SELECT COUNT(DISTINCT country)

FROM customers;


- SELECT DISTINCT BillingCountry, BillingCity

FROM invoices

ORDER BY BillingCountry, BillingCity;