I got that table :
id, user_a, user_b, score
1, 3, 7, 19
2, 8, 3, 20
3, 3, 2, 10
4, 7, 6, 2
5, 3, 6, 7
I achieve counting the number of match per user with :
select user, count(*)
from
(
select user_a as user from tablename
union all
select user_b from tablename
) dt
group by user
I now want to add user email from usertable:
COUNT(*), user, email
4, 3,
[email protected]
2, 7,
[email protected]
1, 8,
[email protected]
1, 2,
[email protected]
2, 6,
[email protected]
I 've tried this :
SELECT user, count(*)
FROM (
SELECT user_a AS user, ut.email
FROM tablename
UNION ALL
SELECT user_b
FROM tablename
) dt
WHERE user IS NOT NULL
LEFT JOIN usertable ut ON ut.id = user
GROUP BY user
but there is a syntax error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LEFT JOIN usertable ut ON ut.id = user
GROUP BY user'
Any idea ?
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)