Mutley Posted March 17, 2007 Share Posted March 17, 2007 I have 2 tables and want 1 query to select 1 field from table_a and 2 fields from table_b then display them using: while($row = mysql_fetch_array( $result )) { echo $row['field1_table_a'], $row['field2_table_b'], $row['field3_table_b']; } ...any assistance would be great. Quote Link to comment https://forums.phpfreaks.com/topic/43176-selecting-2-tables-from-1-query/ Share on other sites More sharing options...
PC Nerd Posted March 17, 2007 Share Posted March 17, 2007 ok but i think it goes like: SELECT table_a.column_name, table_b.column_name, table_b.clolumn_name FROM table_a, table_b WHERE ID = 'VALUE' it will change for your database.... and you have to have a pre set up relationship between the two tables....... i can look it up if you want, but someone probably knows off by heart good luck Quote Link to comment https://forums.phpfreaks.com/topic/43176-selecting-2-tables-from-1-query/#findComment-209651 Share on other sites More sharing options...
Mutley Posted March 17, 2007 Author Share Posted March 17, 2007 Ah, sorry, should of added. For each there will be a different WHERE clause. Quote Link to comment https://forums.phpfreaks.com/topic/43176-selecting-2-tables-from-1-query/#findComment-209654 Share on other sites More sharing options...
Barand Posted March 18, 2007 Share Posted March 18, 2007 How should the tables be joined? which column in first table matches which column in second table? try <?php $sql = "SELECT a.field_1, b.field_2, b.field_3 FROM table_a a INNER JOIN table_b b ON a. field_x = b.field_y WHERE a.field_p = 'something' AND b.field_q = 'somethingelse'"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/43176-selecting-2-tables-from-1-query/#findComment-209693 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.