mySQL lonking table 0 replies

Please wait...


I didn't make it!

0 XP

#1 12 years ago


If i have a table of users and a table of threads, in the table of threads i have field for "created_by_user_id" and also a field for "lastupdated_by_user_id". In the tb_users table i have fields for user_id and user_name

I want to then run a query to show all rows in the tb_threads table and automatically replace the IDs in created_by and updated_by with the relevent usernames from the tb_users table.

In an SQL query I can pull through the actual name of the user who created the thread by doing something like

[/COLOR] [COLOR=black]Code:[/COLOR] [COLOR=black]SELECT `tb_threads`.`thread_id`,`tb_threads`.`createdby_user_id`,`tb_threads`.`th_subject`,`tb_threads`.`th_body`, `tb_users`.`user_name`FROM `tb_threads`, `tb_users` WHERE `tb_threads`.`created_by_user_id` = `tb_users`.`user_id`ORDER BY `tb_threads`.`th_lastupdated` DESCLIMIT 0,30[/COLOR] [COLOR=black]in the same query I want it to replace the id of the "lastupdated_by" user as well.

how can i make it look up the user_name independantly for created_by and updated_by

There will be another step to what I need once I have the answer to this. In fact, the answer to this might apply to my other problem but I'll wait and see.[/COLOR]