M
M
Maxim Epikhin2018-10-29 16:05:48
MySQL
Maxim Epikhin, 2018-10-29 16:05:48

How to output a query with 2 inner join using SQL?

Hello.
There are 3 tables in the database act_courses , inf_courses and inf_statuses .
act_courses :

  • USER_ID
  • COURSE_ID (number of the course you signed up for)
  • STATUS_ID (status number that shows the action)
inf_courses :
  • ID (course number)
  • NAME (course name)
inf_statuses :
  • ID (status number)
  • NAME (status name)

Structure example:
5bd7052b4c560374408670.png
I need to write a query such that all COURSE_IDs are replaced with their names, all STATUS are replaced with names, and the number of STATUS for each course is counted.
That is, the result will be as follows:
A PERSON (Status = 1) SIGNED UP FOR THE COURSE. And here it is REGISTERED changes according to ID status.
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Kim, 2018-10-29
@kimono

Try something like this:

SELECT inf_courses.name, inf_statuses.name, count(*) cnt FROM act_courses
LEFT JOIN inf_courses ON act_courses.course_id = inf_courses.id
LEFT JOIN inf_statuses ON act_courses.status_id = inf_statuses.id
GROUP BY act_courses.course_id, act_courses.status_id -- для группировки по курсу и статусу
-- либо GROUP BY act_courses.course_id для группировки только по курсу

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question