erhanelu ion erhanelu ion - 1 year ago 51
MySQL Question

Create a count in count in sql select

I have a question: it's possible to create an count in count in sql:
my code is:

SELECT COUNT( DISTINCT p.id_participant ) as number
FROM participation p
INNER JOIN message m ON
AND p.id_event = 4

I want to add in first count another count from table winners with count (id_winner)
Help me please, Exist a solution?

Answer Source

You need to use the aggregate function SUM.

For example,

  2  FROM  (SELECT Count(*) VAL
  3         FROM   emp
  4         UNION
  5         SELECT Count(*) VAL
  6         FROM   dept);