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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:08:14+00:00 2026-05-25T15:08:14+00:00

I have two table (question table and answer table). Question Table id question 1

  • 0

I have two table (question table and answer table).

Question Table

id question
1  what is your name?
2  how old are you?

Answer Table

id  answer  questionid
1   john     1
2   smith    1
3   waiyan   1
4   20       2
5   21       2
6   22       2

When I selected records,The results is following.

SELECT * FROM question INNER JOIN answer on questionid= question.id

what is your name?
john
what is your name?
smith
what is your name?
waiyan
how old are you?
20
how old are you?
21
how old are you?
22

I want to remove duplicate question statement.
I want to get following.

What is your name?
John
smith
waiyan  

how old are you?  
20 
21    
22

Please Someone help me how to write it.
I am really beginner for mysql.
So sorry for my bad english usage.

  • 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-25T15:08:14+00:00Added an answer on May 25, 2026 at 3:08 pm

    The issue is in your php code, not your MySQL statements. You need to only print the question when it’s different from the previous question. There are lots of ways to do this. Keep in mind that in your SQL query, you’ll need to do:

    SELECT * FROM question INNER JOIN answer 
        on questionid= question.id 
        order by question.id
    

    To be sure that answers for the same question are not repeated. Then do something like the following (thanks to @drrcknlsn for fixing my attempt at php):

    $last_question = "";
    foreach ($results as $row) {
        if ($last_question !== $row["question.question"]) {
            echo $row["question.question"];
        }
        echo $row["answer.answer"];
        $last_question = $row["question.question"];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, so say I have two tables. Question questionID QuestionDescription Answer AnswerID QuestionID AnswerDescription
I have two tables: Table 1: ID, PersonCode, Name, Table 2: ID, Table1ID, Location,
I have two tables: <class name=Content table=language_content lazy=false> <composite-id> <key-property name=contentID column=contentID/> <key-property name=languageID
I have two tables (well, two relevant for this question) : Bets (holds the
I have two tables: a source table and a target table. The target table
I have two fields in a table. One contains values such as BTA, BEA,
I have two tables in my database: NEWS table with columns: id - the
I have two functions to add and remove table rows that contain a form
I have two identical tables and need to copy rows from table to another.
I have two simple tables in my database. A card table that contains Id,

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.