-1

I have two tables. One is for member info, the other is for board info. I want to display both 'writer' and 'viewer' with name but I can only show one of them by 'LEFT JOIN'

SELECT * FROM `table_a`
idx name    
1   Admin   
2   Superman    
3   Ironman 
4   Batman  


SELECT * FROM `table_bbs`
idx writer  title       viewer  
1   1       Hi All          0   
2   1       hello           2   
3   2       My name is      3   
4   3       Do not click    4   
    



SELECT bbs.writer, a.name, bbs.title, bbs.viewer FROM `table_bbs` AS bbs
    LEFT JOIN table_a AS a ON a.idx = bbs.writer;
writer  name    title           viewer  
1   Admin       Hi All          0   
1   Admin       hello           2   
2   Superman    My name is      3   
3   Ironman     Do not click    4   

How can I get the name of viewer as well?

Jason Jang
  • 3
  • 1
  • 2
  • 1
    What have you tried so far? Where are you stuck? – Nico Haase Feb 08 '22 at 08:17
  • Re 'solved': [help] [meta] [meta.se] Use google 'site:' keyword, the SO/SE search is poor & literal. Click that you agree with a suggested duplicate Q&A and/or click on an answer's check mark to say it was most helpful. Research before considering asking a question in a post or comment. If you created a solution then post it in an answer post. Find out what comments are for. Please educate yourself on how the site works. PS [mre] – philipxy Feb 08 '22 at 10:25
  • Please before considering posting read the manual/reference & google any error message & many clear, concise & precise phrasings of your question/problem/goal (this post doesn't contain one.), with & without your particular names/strings/numbers, 'site:stackoverflow.com' & tags; read many answers. Reflect your research. – philipxy Feb 08 '22 at 10:30
  • Does this answer your question? [How to get matching data from another SQL table for two different columns: Inner Join and/or Union?](https://stackoverflow.com/a/27682724/3404097) – philipxy Feb 09 '22 at 15:36

1 Answers1

0

if viewer data is get from table_a

SELECT bbs.writer, a.name as writer_name, bbs.title, bbs.viewer, b.name as viewer_name FROM `table_bbs` AS bbs
    LEFT JOIN table_a AS a ON a.idx = bbs.writer
    LEFT JOIN table_a AS b ON b.idx = bbs.viewer
Murosadatul
  • 116
  • 6