The CreatorCon Call for Content is officially open! Get started here.

Database view issue: left join of kb_knowledge with m2m_kb_task

Naresh27
Tera Guru

Hi All,

I would like to left join kb_knowledge table with m2m_kb_task so that I can get articles that do not attached to task as well as articles that were attached to task.

Currently, m2m_kb_task provides articles info. that only attached to tasks, But I would want something like above.

So I tried creating a view with left join as below,

find_real_file.png

View result Showing only inner join:

find_real_file.png

But keeping Left join True or False doesn't change my result as it is only giving inner join(above pic) that means only records that match the condition specified in where clause.

Can anybody suggest how to achieve this.

ctomasi

1 ACCEPTED SOLUTION

Jon Barnes
Kilo Sage

Move the where clause to the second table (m2m_kb_task), like below. You should only need left join true on the second one.



find_real_file.png


View solution in original post

4 REPLIES 4

Jon Barnes
Kilo Sage

Move the where clause to the second table (m2m_kb_task), like below. You should only need left join true on the second one.



find_real_file.png


hey thanks for your response


but that wouldn't give me articles with not attached to task anytime


this is my requirement and I need it very badly



this worked well in SQL I got what I want.


Can you please confirm why I cannot or shouldn't use left join on kb_knowledge


thanks


yes it should give you articles not attached to tasks. did you try to set up your DB view like this image below? It will pull all kb_knowledge articles first, and then will left join the m2m_kb_task table to that and the where clause needs to go on that second one. If you set it up like below it should give you what you want, as I did this in my personal instance and it worked fine.



find_real_file.png


Community Alums
Not applicable

Jonathan is correct here. The left join here is going to get all the records from the "left" table here, kb_knowledge, whether it has a corresponding record in the m2m table or not. If you're interested in a different, but similar example with some visuals, take a look at How Do You Report on Nothing?



Good luck, Nari!



Ben