I have a table containing the last comments posted on the website, and I'd like to join a different table depending on the comment type.
Comments Table is similar to this structure:
id | type | ressource_id |
---+------+--------------+
1 | 1 | 10 |
2 | 3 | 7 |
3 | 3 | 12 |
4 | 1 | 22 |
5 | 4 | 22 |
6 | 5 | 23 |
News Table:
news_id | notes| date |
--------+------+--------------+
10 | | 2015-08-12 |
22 | | 2015-07-12 |
Tutorial Table:
tuto_id | notes| date |
--------+------+--------------+
7 | | 2015-06-15 |
12 | | 2015-05-14 |
... Similar table for type = 4, 5, 6
Now in order to get specific comments I am doing a left join on the two tables.
SELECT co.*
FROM Comments co
LEFT JOIN News n
ON co.id = n.news_id AND co.type = 1
LEFT JOIN Tutorial t
ON co.id = t.tuto_id AND co.type = 3
WHERE (co.type IN (1,3))
I am interested in getting the date from the left table. How can I include that column in output list.
Result desired: (date from joining table)
id | type | ressource_id | date |
---+------+--------------+--------------+
1 | 1 | 10 | 2015-08-12 |
2 | 3 | 7 | 2015-06-15 |
3 | 3 | 12 | 2015-05-14 |
4 | 1 | 22 | 2015-07-12 |
Thanks.
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)