[thelist] mysql select query

kris burford [midtempo] kris at midtempo.net
Thu Apr 4 09:08:01 CST 2002


> >select stuff from stories where published is not null and, if its a news
> > story or a feature story, make sure live is not null, order by random
> limit 3
> >
<snip>
>SELECT * FROM $db.$table WHERE ((SectionID = $SectionID AND Live = 1) OR
>(Section ID = $SectionID2 AND Live = 1)) AND Published = 1 ORDER BY
>RAND() LIMIT 3

<snip>
 >where published is not null and ((not news and not feature) or live is
not null)

<snip>
 >select * from stories where published is not null and (storytype not in
('news', 'feature') or live is not null) order by random limit 3

three (to me) different answers (plus steve who kindly pointed out to me
that i should have normalised the table structure to separate out story
categories and relations)

um, let's say that i've just got one table (which i have) and that there
are a lot of different story categories (which are defined by name rather
than number) and that there are only a couple of categories from which i
want to exclude the archived stories... which is right?

kris



More information about the thelist mailing list