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

 

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

 

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.