sweethoney avatar

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

sweethoney

Published: 08 Jun 2024 › Updated: 08 Jun 2024How to refer the foreign key in correspond table to reference table

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

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;

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

Written by

Read more #sql posts


Best Posts From sweethoney

We have not curated any of sweethoney's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From sweethoney