Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 keep multiple values from creating multiple record

Author  Topic 

mty
Starting Member

1 Post

Posted - 2012-03-08 : 17:51:35
Hello! I appreciate any help you might be able to lend in advance....

I am trying to create a query that returns a value for a story (unique ID "news_story"."id"), the pub_date and status (fields in table news_story) among other info including the author(s)( based on the unique ID in table news_story_bylines). In some instances, there are multiple authors, and this is where I run into a problem. When I select a story_ID where more than one author is present, it serves up multiple records - duplicating the story_ID and everything except for the authors. What I need to return is one single record that denotes one story_name, one story_date, etc., with the multiple authors listed within that single record, regardless of the number of authors.

Here is the query I have thus far.....


SELECT "news_story"."id", "news_story"."slug", "news_story"."pub_date", "news_story"."status", "news_story_categories"."story_id", "news_story_categories"."category_id", "news_story_bylines"."id", "news_story_categories"."id", "staff_staffmember"."first_name", "staff_staffmember"."last_name"
FROM "mainDB1"."public"."news_story_categories" "news_story_categories" INNER JOIN (("mainDB1"."public"."news_story_bylines" "news_story_bylines" INNER JOIN "mainDB1"."public"."staff_staffmember" "staff_staffmember" ON "news_story_bylines"."staffmember_id"="staff_staffmember"."id") INNER JOIN "mainDB1"."public"."news_story" "news_story" ON "news_story_bylines"."story_id"="news_story"."id") ON "news_story_categories"."story_id"="news_story"."id"
WHERE "news_story"."status"=1 AND "news_story"."pub_date">={ts '2012-03-05 00:00:00'} AND "news_story_categories"."category_id"=18


Once again, many thanks for a shove in the right direction....

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-03-08 : 17:58:44
see the below example in scenario3

http://visakhm.blogspot.com/2010/01/multipurpose-apply-operator.html



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -