mysql - Joining multiple columns from table a to one on table b -


i've spent bit of time researching on here , mysql site i'm bit confused on 2 things: sort of join use , how (or if) use alias.

the query:

select forum_threads.id, forum_threads.forum_id, forum_threads.sticky,  forum_threads.vis_rank, forum_threads.locked, forum_threads.lock_rank, forum_threads.author_id, forum_threads.thread_title, forum_threads.post_time,  forum_threads.views, forum_threads.replies, users.username author_username  forum_threads left join users on forum_threads.author_id = users.id forum_threads.forum_id=xxx 

now query finds threads given forum , joins threads author id username table. have lastpostid i'd include in query , join again on users table can username last poster too.

i tried adding:

left join users on threads.lastpostid = users.username  

but results in alias error users isn't unique.

i tried using both alias on main query , on second join keeps giving me missing field errors.

could give me point in right direction please?

yes, need different alias each time. every time refer table in query should use approprate alias.

select      forum_threads.id,      -- etc...,      forum_threads.replies,      u1.username author_username       u2.username last_post_username  forum_threads left join users u1 on forum_threads.author_id = u1.id left join users u2 on threads.lastpostid = u2.username  forum_threads.forum_id=xxx 

Comments

Popular posts from this blog

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

c++ - How do I get a multi line tooltip in MFC -

unit testing - How to mock PreferenceManager in Android? -