Jump to content

Select over multiple table with offset records.


Beauford

Recommended Posts

Hi,

 

I have a DB with two tables, customers and orders. One customer may have many orders, What I want to do is do a select on the two tables and get the customer info once, and then all the orders associated with the account.

 

I saw how to do this once before using a join and then having to use a PHP foreach to break it up. I am just not sure of how to put the two together to make it work, or maybe there is an easier way completely.

 

Any help is appreciated.

 

Thanks

 

B

 

Example:

 

Bob Smith

Shoes

Coat

Boots

Gloves

 

Sally Jones

Hat

Purse

Boots

Umbrella

 

Link to comment
Share on other sites

I am not quite sure what you are asking, however, it is a good thing that you have this information in 2 tables.

One table would be something like 'customers' and another table would be something like 'inventory' and a third table would be something like 'orders'.

 

Your 'customers' table would have column's (or) fields like:

Customer_ID <-- primary key

Customername

Customer Address

etc....

 

Your 'inventory' table would have column's (or) fields like:

Inventory_ID  <-- primary key

Item_name

Item_location

Item_cost

Item_size

etc...

 

And your 'orders' table would have column's (or) fields like:

Invoice_ID  <--- primary key

Customer_ID

Inventory_ID

Order_date

etc...

 

This way, you can keep the appropriate info in the appropriate tables.

 

You could search like SELECT * FROM Orders WHERE Invoice_ID="2000"

This would give you all of the information about that particular invoice.

 

Hopefully that gives you a decent start.

 

Terry Mullins

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

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