I get this error: Error in query_privmsgs: Unknown column 'mt.key' in 'on clause'
The third table is "phpbb_users" and the only field I want to select out of that is "username"
Main Topics
Browse All TopicsI've got three tables that I want to join with one SQL statement. I got two of them working, but this won't order the responses by the DESC view. I need the following code to order the responses by the ID DESC and then to add a third table in the SQL statement as well (that's listed below my code). Any ideas?
$query_privmsgs = "SELECT DISTINCT phpbb_privmsgs.privmsgs_su
phpbb_privmsgs_text.privms
FROM phpbb_privmsgs LEFT OUTER JOIN phpbb_privmsgs_text
ON phpbb_privmsgs.privmsgs_id
$result_privmsgs = mysql_query($query_privmsg
query_privmsgs: " . mysql_error());
while ($row_privmsgs = mysql_fetch_array($result_
{
echo "<br><b>Subject</b> : " . $row_privmsgs['privmsgs_su
echo "<br><b>From:</b> " . $row_privmsgs['privmsgs_fr
echo "<br><b>To:</b> " . $row_privmsgs['privmsgs_to
echo "<br><b>Message</b> : " . $row_privmsgs['privmsgs_te
echo "<br>";
}
?>
The third table is phpbb_users and the field I want to add in there is called username (this essentially associates the ID's with an actual username).
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Here's my code that's producing the error:
$query_privmsgs = "SELECT DISTINCT m.privmsgs_subject, m.privmsgs_from_userid, m.privmsgs_to_userid, mt.privmsgs_text FROM phpbb_privmsgs m LEFT OUTER JOIN phpbb_privmsgs_text mt ON m.privmsgs_id = mt.privmsgs_text_id INNER JOIN phpbb_users t ON mt.key = t.key ORDER BY m.privmsgs_from_userid DESC"; // Get newest messages
Sorry, i didn't inform u to substitute the place-holders in that query.
Replace the u.user_id below with the key column of the users table.
Use this :
$query_privmsgs = "SELECT DISTINCT m.privmsgs_subject, m.privmsgs_from_userid, m.privmsgs_to_userid, mt.privmsgs_text FROM phpbb_privmsgs m LEFT OUTER JOIN phpbb_privmsgs_text mt ON m.privmsgs_id = mt.privmsgs_text_id INNER JOIN phpbb_users u ON u.user_id = m.privmsgs_from_userid ORDER BY m.privmsgs_from_userid DESC";
Business Accounts
Answer for Membership
by: jinesh_kamdarPosted on 2008-01-11 at 07:33:21ID: 20637169
>> I need the following code to order the responses by the ID DESC
To order by a field, it needs to be included in the SELECT list as well.
$query_privmsgs = "SELECT DISTINCT m.privmsgs_subject, m.privmsgs_from_userid, m.privmsgs_to_userid, mt.privmsgs_text FROM phpbb_privmsgs m LEFT OUTER JOIN phpbb_privmsgs_text mt ON m.privmsgs_id = mt.privmsgs_text_id INNER JOIN table_3 t ON mt.key = t.key ORDER BY m.privmsgs_from_userid DESC";