[thelist] sql query help

Chris Blessing webguy at mail.rit.edu
Fri May 24 09:51:01 CDT 2002


(I sent this earlier but it didn't come through either, so I also apologize
for a repost! I'm just that deperate)

Hi all-

I've been stumped on a query for the last 20 minutes so I'm hoping someone
can help me out here.

What I have is a setup like this:

myTable: article_id, paragraph_id, sort_order

There can be multiple paragraphs per article, and they are ordered (through
the article) by sort_order.

Now for some reason the program I used to import a bunch of articles has
given a lot of these articles non-incremental sort_orders, so one article
might show up like this:

1,1,1
1,2,1
1,3,1
1,4,1

So article 1 has 4 paragraphs, and they're all sorted as paragraph #1.  This
is no good for obvious reasons! ;)

What I need to do is get a list of all the articles (article_id for each)
which have this problem (the sort_order being 1 and only 1).  Trouble is
that EVERY article in the table (all 5300 of them) has at least one
sort_order = 1, so I need to single out the articles that ONLY have a
sort_order of 1 for every paragraph.

I thought something like this might work but it just returns some arbitrary
number of articles...

select article_id from paragraphs
where sort_order = 1
group by article_id
having count(article_id) > 1

rudy, anyone, help! =)  I'm gonna continue to play around with this.  Thanks
in advance!

Chris Blessing
webguy at mail.rit.edu
http://www.330i.net




More information about the thelist mailing list