0

I'm querying a table from a third party plugin so I don't have control over how the data is being inputted. It's a course plugin broken into 4 different quizzes. One of the questions is being used in all four quizzes.

THERE IS NO "quiz_id" which is why I think they only way to query data is with some sort of if conditional. There IS a date field and a unique id field.

This is what my subquery looks like:

(SELECT y.post_content
FROM wp_posts AS y
WHERE 137 = y.post_author
AND y.post_title LIKE '%If you checked "Other" in "What are your organization’s primary goals related to hiring people with autism?", please explain%'
ORDER BY y.post_author ASC limit 1)

This works to query the answer (y.post_content) for the first quiz, but not for all 4 quizzes. Is there a conditional I can use for this? i.e. let's say i'm querying results for the 2nd quiz: if there are four answers, pick the 2nd one,if there are 3 answers pick the 2nd one, if there are 2 answers, pick the most recent one

enter image description here

  • There's no `wp_users` table in your query. Do you want to get second per ID or for all IDs? – astentx Dec 13 '20 at 20:48
  • Does this answer your question? [Get top n records for each group of grouped results](https://stackoverflow.com/questions/12113699/get-top-n-records-for-each-group-of-grouped-results) – astentx Dec 13 '20 at 20:49
  • the "Get top n records..." question isn't what I'm looking for. – phillystyle123 Dec 13 '20 at 20:55
  • wp_users.id is just the user id (it's in the larger query). it could be WHERE 137 (the user id) = y.post_author – phillystyle123 Dec 13 '20 at 20:56
  • It is really hard for me to correlate between quizes, authors and answers. You filter by single author, but I don't see any quiz_id column and date column (to call some answer as *most recent*). You ask to get answers for all 4 quizes, but want to filter answer for the second quiz without quiz_id filter. Can you provide some sample data and desired output? What will be the output if user didn't complete second quiz and you have only one answer but want to check answers for quiz 2 and 3? – astentx Dec 13 '20 at 21:28
  • Am I right that your *2nd one* answer have something about number 2 in *2nd* quiz and for 3rd it will be 3? – astentx Dec 13 '20 at 21:35
  • thanks for your help - i'll try to clarify – phillystyle123 Dec 13 '20 at 21:42

0 Answers0