tags:

views:

73

answers:

2
<?php

$query = mysql_query("SELECT * FROM threads 
                          INNER JOIN accounts
                          ON threads.author = accounts.id 
                          WHERE id = ".intval($_GET['threadID']));
$row = mysql_fetch_assoc($query);

$title = $row['title'];

?>

What if I have a column named the same in both tables? (title) How does it know which one to get? How can I tell it to get it from accounts table not threads without have different name on them.

+2  A: 

Just qualify it like you do in your inner join.

WHERE accounts.id = 'something'
Chris Farmer
+5  A: 

You can use an alias to fetch the column with a different name

SELECT t.*, a.title AS account_title 
FROM threads t INNER JOIN accounts...

If you only want to fetch the accounts title, list the columns from threads that you DO want

SELECT t.wanted_column, t.another_column, a.* 
FROM threads t, INNER JOIN accounts a...
David Caunt