Title: Problem with SQL Query
Last modified: June 10, 2023

---

# Problem with SQL Query

 *  Resolved [mlapl1](https://wordpress.org/support/users/mlapl1/)
 * (@mlapl1)
 * [2 years, 11 months ago](https://wordpress.org/support/topic/problem-with-sql-query/)
 * Hello. I have an SQL query. Here it is:
 *     ```wp-block-code
       SELECTu.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 scoreFROMwp_users uINNER JOIN wp_learndash_user_activity a ON u.ID = a.user_idINNER JOIN wp_posts c ON a.course_id = c.IDINNER JOIN wp_posts q ON a.post_id = q.IDINNER JOIN wp_learndash_user_activity_meta m ON a.activity_id = m.activity_idWHEREa.activity_type = 'quiz' AND m.activity_meta_key = 'score' AND a.user_id=$$USERID$$ORDER BYusername ASC,start_time DESCLIMIT 500000000 OFFSET 0
       ```
   
 * Its 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.

 * ![](https://ps.w.org/wp-data-access/assets/icon-256x256.png?rev=3299063)
 * [WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards](https://wordpress.org/plugins/wp-data-access/)
 * [Support Threads](https://wordpress.org/support/plugin/wp-data-access/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-data-access/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-data-access/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-data-access/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [mlapl1](https://wordpress.org/support/users/mlapl1/)
 * Last activity: [2 years, 11 months ago](https://wordpress.org/support/topic/problem-with-sql-query/)
 * Status: resolved