dtyson2000 Posted March 3, 2007 Share Posted March 3, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/41019-multiple-table-query-group-by/ Share on other sites More sharing options...
fenway Posted March 3, 2007 Share Posted March 3, 2007 I'm not sure what you're trying to accomplish. Quote Link to comment https://forums.phpfreaks.com/topic/41019-multiple-table-query-group-by/#findComment-198628 Share on other sites More sharing options...
dtyson2000 Posted March 3, 2007 Author Share Posted March 3, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/41019-multiple-table-query-group-by/#findComment-198631 Share on other sites More sharing options...
artacus Posted March 3, 2007 Share Posted March 3, 2007 By table you mean an html table? If you want to get 3,6 then use GROUP_CONCAT() Otherwise, just query it and only display the info you want Quote Link to comment https://forums.phpfreaks.com/topic/41019-multiple-table-query-group-by/#findComment-198714 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.