Welcome to WebmasterWorld Guest from 54.205.20.160

Forum Moderators: open

Message Too Old, No Replies

Adding a Second Table into Query

MySQL

   
11:24 pm on Dec 23, 2009 (gmt 0)

5+ Year Member



Here's my prob, finally got the first part working but I need to add in another table to this query. The below table is the "messages" table that stores all the different messages in a threaded system.

SELECT * FROM (SELECT thread, MAX(id) AS id FROM messages GROUP BY thread) t1 INNER JOIN messages t2 ON t2.thread=t1.thread AND t1.id=t2.id WHERE tome = '$userid' AND INDELETE !='y' ORDER BY t1.id DESC

My problem is I need to pull out the fields "firstname", "lastname" and "image1" of the user sending the message to the person from the table "users" where the field "fromme" in the messages table is = to the "id" field in the users table. Any ideas? THANKS! JC

11:54 pm on Jan 4, 2010 (gmt 0)

WebmasterWorld Senior Member whoisgregg is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Welcome to WebmasterWorld, cussbee!

Maybe something like this would do the trick?

SELECT * 
FROM ( SELECT thread, MAX(id) AS id FROM messages GROUP BY thread ) AS t1
INNER JOIN
messages AS t2 ON t2.thread=t1.thread AND t1.id=t2.id
INNER JOIN
users AS t3 ON t3.id=t1.fromme
WHERE tome = '$userid' AND INDELETE !='y'
ORDER BY t1.id DESC

Kind of hard to tell because I'm not really sure what's going on with the current temporary table and inner join. But, hopefully this will point you in a direction if you haven't already sorted this out. :)

 

Featured Threads

Hot Threads This Week

Hot Threads This Month