1

I have a pet project on feedback system with to tables, one caputres the questions of customers and another caputures the answeers of help desk.


////////////////////////////////////////////////////////////////////////
Customers_Question table         AND   helpdesk_answers  includes: 
Qst_id(pk),                            Qst_id(pk)(FK)
qst_title,                             helpdesk_answer
qst_comment,
qst_customer_name, 
qst_date

to get answers mysql query is:

SELECT*from customers_question, helpdesk_answers
WHERE customers_qst.Qst_id = helpdesk_answers(FK Qst_id)

i get all questions that already answered. QUESTION: HOW DO I GET OR COUNT UNANSWERED QUESTION?

karthikr
  • 92,866
  • 25
  • 190
  • 186
PULabs
  • 39
  • 2
  • 8

3 Answers3

2
SELECT q.* 
from customers_question q
left join helpdesk_answers a on q.Qst_id = a.Qst_id
where a.Qst_id is null

See this great explanation of joins

juergen d
  • 195,137
  • 36
  • 275
  • 343
0

using IS NULL ->

SELECT cq.* FROM customers_question cq 
LEFT JOIN helpdesk_answers ha 
    ON cq.Qst_id = ha.Qst_id 
WHERE ha.Qst_id IS NULL

OR

using NOT IN() ->

SELECT * FROM customers_question 
WHERE Qst_id NOT IN 
     (SELECT DISTINCT Qst_id FROM helpdesk_answers)
Sean
  • 12,439
  • 3
  • 27
  • 46
0

You can use the code given in the other answers to get the questions.

In order to count the rows returned you can see this answer.

Community
  • 1
  • 1
ppp
  • 1,985
  • 8
  • 30
  • 52