X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 7D5EA9FB22A for ; Sat, 8 Jul 2006 07:35:20 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 29149-03 for ; Sat, 8 Jul 2006 07:35:05 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from web51910.mail.yahoo.com (web51910.mail.yahoo.com [206.190.48.73]) by postgresql.org (Postfix) with SMTP id 6883F9FB22B for ; Sat, 8 Jul 2006 07:35:05 -0300 (ADT) Received: (qmail 45213 invoked by uid 60001); 8 Jul 2006 10:35:03 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=3Dy24G0pb4KHTGm55vVyUBuupjQTqUDqYtesXWl8X/GE8z3Y0Os1LN7iTJnYDNr0LBEq0eZPx17YwYdZazbqPJnFqo4n0HylB5ib7cQ1Z+vSGhLwOPCZQoPZ+MHwcjnCyVl7PXwLRlghbUoxAbFj0g3YbqZW0zs2Ugy1MnhGhVg= ; Message-ID: <20060708103503.45211.qmail@web51910.mail.yahoo.com> Received: from [203.181.127.181] by web51910.mail.yahoo.com via HTTP; Sat, 08 Jul 2006 11:35:03 BST Date: Sat, 8 Jul 2006 11:35:03 +0100 (BST) From: Anthony Kinyage Subject: Re: table joining duplicate records To: onin Cc: pgsql-sql@postgresql.org In-Reply-To: <44AF748C.2010100@mobius.ph> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-260182870-1152354903=:42915" Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200607/130 X-Sequence-Number: 25704 --0-260182870-1152354903=:42915 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit In your case Survey , Categories, Questions and Answers TABLES are parents tables, and Question_answers TABLE is a Child Table. Since you want to have survery, from Survey Table, Category from Category Table, Question from Question Table and Answer from Answer Table and alll these Atributes are on Question_answer Table, in your case you can use the following: SELECT * FROM question_answer; Try this STATEMENT onin wrote: hi all, somebody please help me with my sql statement. or point me to the right documentation that i need to read. what i want to working on right now is to create a db for a survey app my tables look this surveys survey_id:survey ---------------- 1 : survey1 categories category_id:category ---------------- 1 :category1 questions question_id:question ---------------- 1 :question1 answers answer_id:answer ---------------- 1 :answer1 2 :answer2 questions_answers question_answer_id:survey_id:category_id:question_id:answer_id 1 :1 :1 :1 1 :1 :1 :2 and my query looks like this select s.survey, c.category, q.question, a.answer from questions_answers qa, answers a, questions q, categories c, surveys s where qa.answer_id = a.answer_id and qa.question_id = q.question_id and qa.category_id = c.category_id and qa.survey_id = s.survey_id; after executing the code, i get results like this. --query results-- survey :category :question :answer survey1:category1:question1:answer1 survey1:category1:question1:answer2 how can i elimate duplicates on my query results? an also am i using the right 'table joining' or table design for my survey app? any help would be appriciated. thanks in advance. -- "A whim, a thought, and more is sought... awake, my mind... thy will be wrought!" ---------------------------(end of broadcast)--------------------------- TIP 2: Don't 'kill -9' the postmaster --------------------------------- Try the all-new Yahoo! Mail . "The New Version is radically easier to use" – The Wall Street Journal --0-260182870-1152354903=:42915 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: 8bit
In your case Survey , Categories, Questions and Answers TABLES are parents tables, and Question_answers TABLE is a Child Table.
 
Since you want to have survery, from Survey Table, Category from Category Table, Question from Question Table and Answer from Answer Table and alll these Atributes are on Question_answer Table, in your case you can use the following:
 
 
SELECT * FROM question_answer;
 
Try this STATEMENT


onin <jnana@mobius.ph> wrote:
hi all,

somebody please help me with my sql statement.
or point me to the right documentation that i need to read.

what i want to working on right now is to create a db for a survey app
my tables look this

surveys
survey_id:survey
----------------
1 : survey1

categories
category_id:category
----------------
1 :category1

questions
question_id:question
----------------
1 :question1

answers
answer_id:answer
----------------
1 :answer1
2 :answer2

questions_answers
question_answer_id:survey_id:category_id:question_id:answer_id
1 :1 :1 :1
1 :1 :1 :2

and my query looks like this

select s.survey, c.category, q.question, a.answer from questions_answers
qa, answers a, questions q, categories c, surveys s
where qa.answer_id = a.answer_id and qa.question_id = q.question_id and
qa.category_id = c.category_id and qa.survey_id = s.survey_id;


after executing the code,
i get results like this.

--query results--
survey :category :question :answer
survey1:category1:question1:answer1
survey1:category1:question1:answer2

how can i elimate duplicates on my query results?
an also am i using the right 'table joining' or table design for my
survey app?


any help would be appriciated.
thanks in advance.

--
"A whim, a thought, and more is sought... awake, my mind... thy will be wrought!"



---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster




Try the all-new Yahoo! Mail . "The New Version is radically easier to use" – The Wall Street Journal --0-260182870-1152354903=:42915--