in Education by
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)

1 Answer

0 votes
by
Do a UNION ALL in a derived table, to get one column of users. GROUP BY it's result. select user, count(*) from ( select user_a as user from tablename union all select user_b from tablename ) dt group by user Answer to updated question: SELECT dt.user, ut.email, count(*) FROM ( SELECT user_a AS user FROM tablename UNION ALL SELECT user_b FROM tablename ) dt LEFT JOIN usertable ut ON ut.id = dt.user GROUP BY dt.user, ut.email

Related questions

0 votes
    I got that table : id, user_a, user_b, score 1, 3, 7, 19 2, 8, 3, 20 3, 3, ... JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 3, 2022 in Education by JackTerrance
0 votes
    The tables are: 1) Producers: id, name 2) Products: id, name, price, category_id, producer_id 3) ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 11, 2022 in Education by JackTerrance
0 votes
    We are in the process to update an existing WordPress website and imported posts from one site to another. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 22, 2022 in Education by JackTerrance
0 votes
    We are in the process to update an existing WordPress website and imported posts from one site to another. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    We are in the process to update an existing WordPress website and imported posts from one site to another. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    We are in the process to update an existing WordPress website and imported posts from one site to another. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 1, 2022 in Education by JackTerrance
0 votes
    Im trying to insert the current date and a specific time into a table this is my query INSERT INTO ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    Im trying to insert the current date and a specific time into a table this is my query INSERT INTO ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    Hi I have two tables here: Transcript Grade Student_number Course_number Semester Year A 8 MATH2410 Fall 07 ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    Hi I have two tables here: Transcript Grade Student_number Course_number Semester Year A 8 MATH2410 Fall 07 ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    It is given that in a group of 3 students, the probability of 2 students not having the same birthday is 0. ... have the same birthday? Select the correct answer from above options...
asked Nov 25, 2021 in Education by JackTerrance
0 votes
    It is given that in a group of 3 students, the probability of 2 students not having the same birthday is 0. ... the same birthday ? Select the correct answer from above options...
asked Nov 25, 2021 in Education by JackTerrance
0 votes
0 votes
0 votes
    From a group of 3 boys and 2 girls, we select two children. What would be the sample space for this experiment ? Select the correct answer from above options...
asked Nov 15, 2021 in Education by JackTerrance
...