Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7636825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:46:57+00:00 2026-05-31T07:46:57+00:00

This is the first time – I’m trying to do something like this –

  • 0

This is the first time – I’m trying to do something like this – so please bear with me.
This is on MySql.

I am trying to generate a report to see which students have completed which topics and on which dates.

This is the current query that I run

select u.email,t.topic_name,tu.date_created as 'date completed'
from topic_user tu
join topic t ON tu.topic_id = t.topic_id
join user u ON tu.user_id = u.user_id

which will return results like

email         |    topic_name      |    date completed
abc@gmail.com |    ABC             |    03/01/2012
abc@gmail.com |    DEF             |    03/02/2012
abc@gmail.com |    ABC             |    03/08/2012
abc@gmail.com |    GHI             |    03/08/2012
def@gmail.com |    ABC             |    03/02/2012
def@gmail.com |    XYZ             |    03/10/2012

The way I want to generate the report is have the topic names as column headers and the date they completed it as values

email         |    ABC      |    DEF      |    GHI      |    JKL      |    XYZ     
abc@gmail.com | 03/08/2012  | 03/02/2012  | 03/08/2012  |    null     |    null
def@gmail.com | 03/02/2012  |    null     |    null     |    null     |  03/10/2012

Few things to note are:

1) All the topic names would come from the topic table – even if they have not been completed by the students – the value should appear as null

2) Incase of student abc@gmail.com – he has studied the topic ABC twice – but the report should get the latest date.

I guess I have to write a stored procedure to accomplish this. Like maybe first pull all the topic names from the topic table and then create a temp view and populate it.

I would appreciate any help you can provide.
Thanks much

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T07:46:58+00:00Added an answer on May 31, 2026 at 7:46 am

    I’ve not tested this, and my experience with MySQL is limited but I hope the below is what you are after. It dynamically creates the SELECT statement using the GROUP_CONCAT function, then executes it (This is the bit I am not certain of the way to do it in MySQL).

    SET @SQL = (
    SELECT  CONCAT('SELECT Email,', GROUP_CONCAT(SelectText), ' FROM Topic_User tu INNER JOIN Users u ON u.User_ID = tu.User_ID GROUP BY Email')
    FROM    (   SELECT  CONCAT(' MAX(CASE WHEN Topic_ID = ', Topic_ID, ' THEN tu.Date_Created END) AS `', Topic_Name, '`') AS SelectText
                FROM    Topic
            )  AS d);
    
    PREPARE stmt FROM @SQL;
    EXECUTE stmt
    

    Of course if your topics are not changing very regularly you could just use:

    SELECT  Email,
            MAX(CASE WHEN Topic_ID = 1 THEN tu.Date_Created END) AS ABC,
            MAX(CASE WHEN Topic_ID = 2 THEN tu.Date_Created END) AS DEF,
            MAX(CASE WHEN Topic_ID = 3 THEN tu.Date_Created END) AS GHI,
            MAX(CASE WHEN Topic_ID = 4 THEN tu.Date_Created END) AS JKL,
            MAX(CASE WHEN Topic_ID = 5 THEN tu.Date_Created END) AS XYZ
    FROM    Topic_User tu
            INNER JOIN users u
                ON u.User_ID = tu.User_ID
    GROUP BY Email
    

    and alter the query each time a new topic is added (This is the query produced by the process above).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is my first time posting here, I have a question which I have
This is the first time I'm trying random numbers with C (I miss C#).
This is my first time making a hash table. I'm trying to associate strings
I am trying to install elastic plugin. This is first time i am installing
$referal = mysql_real_escape_string($_SERVER['HTTP_REFERER']); I would like to store this the first time the visitor
This is first time that I work with json. I am trying to return
I'm using PayPal sandbox for the payment gateway, this is first time I'm trying
This is my first time attempting to call an ASP.NET page method from jQuery.
This is my first time using joomla. I don't know if I'm using the
This is my first time with Web services. I have to develop web services

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.