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
  • 97,368
  • 26
  • 197
  • 188
PULabs
  • 39
  • 2
  • 9

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
  • 201,996
  • 37
  • 293
  • 362
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,443
  • 3
  • 29
  • 47
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
  • 2,035
  • 9
  • 32
  • 52