pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
table joining duplicate records
4+ messages / 3 participants
[nested] [flat]

* table joining duplicate records
@ 2006-07-08 09:02  onin <jnana@mobius.ph>
  0 siblings, 2 replies; 4+ messages in thread

From: onin @ 2006-07-08 09:02 UTC (permalink / raw)
  To: pgsql-sql

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!"





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: table joining duplicate records
@ 2006-07-08 10:35  Anthony Kinyage <kinyage_tony@yahoo.com>
  parent: onin <jnana@mobius.ph>
  1 sibling, 0 replies; 4+ messages in thread

From: Anthony Kinyage @ 2006-07-08 10:35 UTC (permalink / raw)
  To: onin <jnana@mobius.ph>; +Cc: pgsql-sql

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

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: table joining duplicate records
@ 2006-07-08 15:19  Richard Broersma Jr <rabroersma@yahoo.com>
  parent: onin <jnana@mobius.ph>
  1 sibling, 0 replies; 4+ messages in thread

From: Richard Broersma Jr @ 2006-07-08 15:19 UTC (permalink / raw)
  To: onin <jnana@mobius.ph>; pgsql-sql

> --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?

What duplicates?  You have two unique answers for question1.

Regards,

Richard Broersma Jr.



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: table joining duplicate records
@ 2006-07-09 05:56  Richard Broersma Jr <rabroersma@yahoo.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Richard Broersma Jr @ 2006-07-09 05:56 UTC (permalink / raw)
  To: onin <jnana@mobius.ph>; +Cc: pgsql-sql

> can i have a result set. just like the outer join returns.
> but on my case. return null on duplicates.
> like this one.
> 
> survey :category :question :answer
> -----------------------------------
> survey1:category1:question1:answer1
>        :         :         :answer2

hmmm..  I am no sure that you are going to get what you want from a simple select query.

A reporting software could do this easily however.

also be sure to include the list in your replies :-).

Regards,

Richard Broersma Jr.



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2006-07-09 05:56 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-07-08 09:02 table joining duplicate records onin <jnana@mobius.ph>
2006-07-08 10:35 ` Anthony Kinyage <kinyage_tony@yahoo.com>
2006-07-08 15:19 ` Richard Broersma Jr <rabroersma@yahoo.com>
2006-07-09 05:56 Re: table joining duplicate records Richard Broersma Jr <rabroersma@yahoo.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox