Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/43176-selecting-2-tables-from-1-query/
Share on other sites

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

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'";
?>

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.