I want to display the top 20 records so there are no duplicate story_title's.
Main Topics
Browse All TopicsThe query GetStory displays a saved RSS NEWS Feed. The feed has already been grabbed and saved to the database so no reason to get it again. The idea is to display from the database if the WAIT_TIME has expired and not tie up the feed.
I could display just the last 20 entries and order by id desc, but don't want to take a chance and some feeds have less than 20 entries, etc. And anyway, I'd like to know how this can work.
The STORY_TITLE column in the database has exact duplicates. I want to pull only the top 20 so that there are never any duplicate stories with the same story_title.
ID is the database row number with a data type int (4) and with primary key set with identity = yes.
STORY_TITLE is data type varchar (128).
If the STORY_TITLE has a duplicate then its associated CONTENT, RSSLINK, and FEED_POSTED will also be identical. So they're not hepful.
However, POST_DATE, not included here, is always a different date for otherwise matching identical STORY_TITLE's. Perhaps I could make use of this fact?
Show me how to rewrite this query to get it to work the way I want with cf8 standard.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Do you have a sample of the data for the duplicate stories? If the id is the only duplicated field and you don't need the id in your CF page, then you can just eliminate that. If there are other fields that are different between the rows, then please post a sample.
If you were using SQL Server 2005, I was going to suggest an OVER statement with ROW_NUMBER() function. With SQL Server 2000, those don't exist, but can simulate it, but need to see sample of data to make sure understand completely before typing that code.
Additionally, you may be able to group and do aggregates depending on what is different and which you want when different.
<cfquery name="getStories" datasource="daily-news">
SELECT DISTINCT TOP 20 story_title
FROM story
WHERE DB_SCRIPT_NAME = <cfqueryparam cfsqltype="cf_sql_varchar"
AND DateDiff(day, PUBDATE, getDate()) < 90
ORDER BY story_title
</cfquery>
<cfquery name="StoryInfo" datasource="daily-news">
SELECT *
FROM story
WHERE story_title IN (<cfqueryparam cfsqltype="varchar" value="#valuelist(getStori
ORDER BY story_title
</cfquery>
Azadi
Well the syntax was easy enough and after reviewing the original query, I think I understand enough to post what I had in mind. Since you are getting the 20 most recent id values and you also have a date field, I would suspect that these rows are pretty unique aside from duplication in title and so you would probably want the one with most recent id (latest post); therefore, I have done the ranking by the id desc.
You can use ONE query!
azadisaryev:
I had already posted the same basic solution you posted, 45 minutes before you posted it so can't use it this time. But thanks anyway.
So, the points have to go to mwvisa1. I used your next to last answer and it's more elegant than the others. That is, from what I can see.
And thanks for the extra detail. That always helps me decide.
Business Accounts
Answer for Membership
by: PluckaPosted on 2009-08-13 at 19:21:16ID: 25094837
Really dont understand what you want here. If you can explain better, Im sure I could write the query.