Jump to content

Multiple Table Query... Group By?


dtyson2000

Recommended Posts

Hello. Here is what's happening:

 

I need to run a query on a couple of tables.

 

T1:

order_id |cust_name |product_ord

21David3

21David6

 

T2:

cust_name |cust_addr |cust_zip

DavidHollywood Blvd90210

JaneMain St90210

 

Now, the customer orders a couple of products, which go into the database as separate rows. If I try to pull info from both tables, I get two rows for David using something like

 

select t1.*, t2.* from t1, t2 where t1.cust_name = t2.cust_name

 

T3:

order_id |cust_name |cust_addr |cust_zip |product_ord

21DavidHollywood Blvd902103

21DavidHollywood Blvd902106

 

If I try a GROUP BY order_id, the resulting table shows only the last row containing only the order for product 6.

 

The question is, am I even on the right track for combining all info from these two tables into one row?

 

Also, how do you guys do those nicely laid out table examples? Mine look horrible, for which I'm sorry.

 

Thanks, in advance!

Link to comment
https://forums.phpfreaks.com/topic/41019-multiple-table-query-group-by/
Share on other sites

I need to combine those tables into one table (T3) but with multiple rows containing the same information (except for one bit - product_ord), I thought I could combine the rows that have common information (by say the order number).

 

T3:

order_id |cust_name |cust_addr |cust_zip |product_ord

21DavidHollywood Blvd902103, 6 (or even split these values into two cells)

 

I hope that makes more sense. I'm relatively new to this stuff but am learning a lot, thanks to you guys!

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.