Q:

How to remove redundant data while displaying in jsp

I am fetching data from three tables.
I want to display these data in jsp page.
My problem is that after join data are redundant
I dont want to display redundant data.
My tables are
 create table questions(id integer,title varchar(140),body varchar(2000),
 primary key(id));

 create table question_tags(id integer,tag_name varchar(50),question_id integer,
 primary key(id),foreign key(question_id) references questions(id));

create table answers(id integer,answer varchar(2000),question_id integer,
primary key(id),foreign key(question_id) references questions(id));

Query to fetch data
SELECT questions.*,`question_tags`.*, `answers`.* 
FROM `questions`
JOIN  `answers` 
ON `questions`.`id` = `answers`.`question_id`
JOIN `question_tags` 
ON `questions`.`id` = `question_tags`.`question_id`
WHERE `questions`.`id` = '1'

result after fetching data
 ID     TITLE   BODY    TAG_NAME    QUESTION_ID ANSWER
  1     a   hello   java                 1          good
  1     a   hello   java                 1          exellent
  1     a   hello   java                 1          ok
  1     a   hello   mysql                1          good
  1     a   hello   mysql                1          exellent
  1     a   hello   mysql                1          ok
  1         a   hello   jquery               1          good
  1     a   hello   jquery               1          exellent
  1     a   hello   jquery               1          ok

Here I am fatching data using result set and showing in jsp
I want to show following data in my jsp
  question.id|question.title|question.body|tag_names | answers
      1               a           hello       java        good  
                                              mysql       excellent
                                              jquery      ok                               

This was for only few no of rows.
Here total o/p rows are 1*3*3=9
If data are increased in tables  then duplicate data  are increased how to resolve it.
This is sql fiddle for above code

A:

Use distinct clause with your select statement to get no duplicate records  
SELECT distinct questions.*,`question_tags`.*, `answers`.* 
FROM `questions`
JOIN  `answers` 
ON `questions`.`id` = `answers`.`question_id`
JOIN `question_tags` 
ON `questions`.`id` = `question_tags`.`question_id`
WHERE `questions`.`id` = '1'

Updated 
ResultSet rs = st.execute();   //Assuming that you have the resultset

Set<String> id = new LinkedHashSet<String>();
Set<String> body = new LinkedHashSet<String>();
Set<String> tag_name = new LinkedHashSet<String>();
Set<String> answer = new LinkedHashSet<String>();

while(rs.next())
{
    id.add(rs.getString("id"));
    body.add(rs.getString("body"));
    tag_name.add(rs.getString("tag_name"));
    answer.add(rs.getString("answer"));
}

Because of the LinkedHashSet only distinct values will be stored. Now you need to iterate to populate your table  
NOTE : This is limited to a particular question ID

