MySQL Forums
Forum List  »  Newbie

help with a query
Posted by: oliver voegeli
Date: January 31, 2007 09:26AM

Hello

Given two tables:

Table Person:
ID | Age
--------
1  | 45
2  | 32
etc.

Table Answer (ID: Foreign-key which relates to the table Person, 1:n)
ID | QuestionNo | Answer
1  | 1          | 3
1  | 2          | 1
1  | 3          | 2
2  | 1          | 1
etc.

Let's say, each person fills out three questions. Now I would like to have a resultset in which each row represents a person, and each of the three questions (QuestionNo) gets a column of its own, in where you would find the given answer:

Age | Question1 | Question2 | Question3
45  | 3         | 1         | 2
32  | 1   etc.

How should the sql-statement look like?

Thx for any help!
Oliver

Options: ReplyQuote


Subject
Written By
Posted
help with a query
January 31, 2007 09:26AM
January 31, 2007 09:43AM
January 31, 2007 09:52AM
thx
January 31, 2007 10:07AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.