On 28 Feb 2009 in macromedia.dreamweaver.appdev, jeffmg
wrote:
> Thanks for responses - to answer Joe's question, the
records are
> differentiated in the database only by the fact that
some have an
> entry in the description field, some don't. I'm not sure
what I
> would need to do to amend the table so that the entries
with a
> description display first.
> At the moment there are 16 fields - id, contact,
company, address1,
> address2,
> town, county, postcode, country, telephone, fax, email,
web,
> service, products, description - and the only
differentiation is
> that some entries have something in the description
field (enhanced)
> some don't (basic) - should I have another column of
some sort which
> designates which is enhanced and which isn't by using a
1 or 0, or
> have I misread the post below?
No. The SQL statement I provided will give you what you want:
SELECT id, contact, company, address1, address2, town,
county,
postcode, country, telephone, fax, email, web, service,
products,
description, (LENGTH(description) > 0) AS enhanced
FROM myTable
ORDER BY enhanced DESC, products
A bit of explanation:
"(LENGTH(description) > 0) AS enhanced" will return 1 if
there's
anything in the `description` field, and 0 otherwise. ">"
is a boolean
operator which returns either TRUE (1) or FALSE (0). You can
then use
that to sort, and since you want 'enhanced' products to sort
to the
top, the sort should be descending.
A bit more explanation:
You want to do this at selection time. There's a general
principle of
database design that you don't want to store anything in a
database
which you can derive from data in the database. Thus, if you
have
dates of birth, you don't want to also store ages, because as
soon as
one day has passed, the age information is out of date. On
the other
hand, DOB will never be out of date, and you can use it to
determine
age at retrieval time.
Likewise with your system - if the status of the product
changes,
someone will enter or delete the description, but will
inevitiably
forget to change the 'enhanced' field.
--
Joe Makowiec
http://makowiec.net/
Email:
http://makowiec.net/contact.php