0

I have a table:

enter image description here

and this table:

enter image description here

I would like to create report like this

enter image description here

I've tried this SQL:

select master_problem.problem, master_problem.sop_reference, master_problem.adidas_spec, count(log_roving_qc.id_problem) as jumlahfrom master_problem inner join log_roving_qc on master_problem.id_problem = log_roving_qc.id_problem group by master_problem.id_problem 

but the empty data does not show. I want to display blank data with a description of 0

2
  • I have attempted to fix the problems with the query you actually showed us. If you want something other than this, then edit your question and make that more clear. Commented Dec 26, 2017 at 2:25
  • Chang inner join to left join Commented Dec 26, 2017 at 2:26

1 Answer 1

2

Do a left join of the master_problem table to a subquery which does the count aggregation:

SELECT mp.problem, mp.sop_reference, mp.adidas_spec, COALESCE(t.cnt, 0) AS jumlahfrom FROM master_problem mp LEFT JOIN ( SELECT id_problem, COUNT(*) as cnt FROM log_roving_qc GROUP BY id_problem ) t ON mp.id_problem = t.id_problem; 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.