Problem with SQL Query
-
Hello. I have an SQL query. Here it is:
SELECT
u.ID AS user_id,
u.user_login AS username,
c.post_title AS course_name,
q.post_title AS quiz_name,
FROM_UNIXTIME(a.activity_started, '%d-%m-%Y %H:%i') AS display_start_time,
FROM_UNIXTIME(a.activity_completed, '%d-%m-%Y %H:%i') AS display_end_time,
a.activity_started AS start_time,
m.activity_meta_value AS score
FROM
wp_users u
INNER JOIN wp_learndash_user_activity a ON u.ID = a.user_id
INNER JOIN wp_posts c ON a.course_id = c.ID
INNER JOIN wp_posts q ON a.post_id = q.ID
INNER JOIN wp_learndash_user_activity_meta m ON a.activity_id = m.activity_id
WHERE
a.activity_type = 'quiz' AND m.activity_meta_key = 'score' AND a.user_id=$$USERID$$
ORDER BY
username ASC,
start_time DESC
LIMIT 500000000 OFFSET 0Its purpose is to display quiz results from a plugin called Learndash. It is supposed to list the results for the user who is logged in and only that user. It should show the quizzes done beginning with the newest. Now it works perfectly well except that I do not want the LIMIT statement at the end as I do not know how many responses there will be. If I remove the LIMIT statement, the sorting in terms of starting time is oldest to newest. If I bring back the LIMIT statement it correctly sorts from newest to oldest. I have no idea why this is happening or how to fix it. Any ideas?
I also have another problem. At the moment all variables pulled out of the database are displayed in columns. I want to select the columns that appear but there seems no way to do this.
I believe that the solution is to create a project or a form but it looks pretty complex for a query that has joins (at the moment I just do not see how to make them).
Any help with either problem greatly appreciated. Thank you.
Andrew
- The topic ‘Problem with SQL Query’ is closed to new replies.