Jump to content

sharing information between tables


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
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.

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • 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.