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 8923383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:06:11+00:00 2026-06-15T07:06:11+00:00

Hi I’m currently developing a sort of quiz application. In Discover section I get

  • 0

Hi I’m currently developing a sort of quiz application. In “Discover” section I get popular and latest questions. But when I get them I should also check if question is already answered by current user or not.

Here are my tables:
questions: (media_id is primary key, player_id is creator of the question)

media_id - player_id - answer0 - answer1 - ...

answers: (media_id is primary key, player_id is the person who answers the question)

media_id - player_id - result - ...

This is how I get popular questions:

select * from questions where order by popularity_count

EDIT:
Let me show what I want to achieve by examples:

questions rows:

media_id - player_id - answer0 - answer1
0123456    abc123      bla       bla
6543210    hjk789      lor       ips

answers rows:

media_id - player_id - result
6543210    abc123      1

So when user “abc123” gets the popular questions results should be:

media_id - player_id - answer0 - answer1 - is_answered
0123456    abc123      bla       bla       0
6543210    hjk789      lor       ips       1

The problem is I need a temporary column in the result of query that indicates if question is replied by the current user or not. How can I achieve this?

I can find if question is already answered or not for popularity section by using two queries. First I get the popular questions then I simply check if question is answered or not for every questions which seems so ineffective way. How can I achieve this with only one query?

Thank you!

  • 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-06-15T07:06:13+00:00Added an answer on June 15, 2026 at 7:06 am

    It doesn’t seem you are approaching this problem correctly as you have a non-normalized table structure.

    You should have a separate table that contains the answers by row.

    questions (id, media_id, player_id, question)

    answers (id, media_id, player_id, question_id, answer)

    This way you can LEFT JOIN answers to questions and easily see which questions are not answered like so:

    SELECT q.question, a.answer
    FROM question q
    LEFT JOIN answers a ON a.question_id = q.id
      AND a.media_id = q.media_id
      AND a.player_id = q.player_id
    

    See it in action

    To add a column to your current query, you can append it to your SELECT and use a CASE statement to check whether it’s been answered.

    SELECT ..., 
        CASE
            WHEN answer0 IS NOT NULL
                THEN 'Yes'
            ELSE 'No'
        END AS 'Answered'
    FROM ...
    

    Update

    Based on your update, it seems as though you are only JOINing on player_id. I believe you intend to JOIN on both player_id and media_id. See the difference between the data you provided and what I think you intend it to be.

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

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this
I am currently running into a problem where an element is coming back from

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.