Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to join 3 tables, topic, comment and user
    primarykey
    data
    text
    <p>I have 3 tables, tbl_topic, tbl_comment, tbl_user. I want to select all the topics created by the user and also the topics that he commented on even if he is not the creator. Here is my database:</p> <pre><code>tbl_topic ---------- topic_id topic_title user_id tbl_comment ---------- comment_id comment_message user_id topic_id tbl_user ---------- user_id user_name </code></pre> <p>Need it so badly. Thanks!</p> <p>So far i got this</p> <pre><code>select * from tbl_topic T inner join tbl_comment C on T.topic_id = C.topic_id inner join tbl_user U on T.user_id = U.user_id GROUP BY T.topic_id </code></pre> <p>My problem is it only returns the topics that has comments on it. I want to include the topics created by the user even if it has 0 comments.</p> <p>I want the result to be like this:</p> <pre><code> +-----------+-----------+----------+-------------+----------------+----------+------- | topic_id | topic_title | user_id | comment_id | comment_message | user_id | topic_id | +-----------+-----------+----------+-------------+----------------+----------+-------- | 1 | my topic | 1 | 1 | comment me | 1 | 1 | 2 | others | 2 | 2 | comment me | 1 | 2 | 3 | my nocoment| 1 | NULL | NULL | NULL | NULL +-----------+---------+--------+-------------+----------+----------+---------+-------- ----------+-----------+ user_id | user_name | -----------+----------- 1 | me | 2 | someone | 1 | me -----------+---------+-- </code></pre> <p>I messed up with my fields in my tables, the user_id beside comment_message should be comment_user_id but i already created my database that way. Can you help make this possible?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload