Jump to content

sharing information between tables


mindapolis

Recommended Posts

Hi, I have an order table that contains data like product ordered, quantity, price, shipping  information.  I have a customer tables that has name, address etc.  The primary keys for each table are customer_id and order_number.  What is the  best way to link the customer first and last name to the order table.  Can I put them as foreign keys or should I create a query? 

Link to comment
https://forums.phpfreaks.com/topic/262223-sharing-information-between-tables/
Share on other sites

And then when you query it, you can

 

SELECT orders.*, customers.first_name, customers_last_name FROM orders INNER JOIN customers ON orders.customer_id = customers.id

 

to get your customer name related to an order, or

 

SELECT customers.id, COUNT(orders.id) FROM customers LEFT JOIN orders ON customers.id = orders.customer_id

 

to get the number of orders per customer...

 

or lots of other nifty things.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.