The query using JOIN syntax (you can read about this in the documentation) describes the interelationship between the three tables you described, in this way you can select information based on a WHERE clause as it relates to the category table, while still ordering by the business table.

Read up on joins, that may help.

-Micah

Sid Price wrote:
I am sorry but I don't understand the select query you wrote, could you
perhaps explain how it works or point me to a reference that might help me
understand it?

Many thanks for responding,
Sid.

Sid Price Software Design
http://www.softtools.com
-----Original Message----- From: Micah Stevens [mailto:[EMAIL PROTECTED] Sent: Sunday, March 25, 2007 9:23 PM
To: [EMAIL PROTECTED]; mysql@lists.mysql.com
Subject: Re: Sorting Problem

This doesn't work?

SELECT businesses.name from businesses
left join links using (businessID)
left join categories using (categoryID)
where category.name = 'something'
order by businesses.name ASC



On 03/25/2007 12:40 PM, Sid Price wrote:
Hello,

I have a MySQL database design that provides an online business directory.
It consists of three tables; one with the names and addresses of the
businesses (names), one with the categories of businesses (categories),
and
one that has an entry (a category ID and a business ID) for each
business/category pairing (entries), a business may be in multiple
categories.

The problem I am having is after having queried the "entries" table for
all
the entries for a given category I query the "names" table for each entry
to
display the business name and address, I can not figure a way to sort the
displayed data by company name, The "entries" table holds the business ID
and category ID so sorting the entries that match the category doesn't
help.
Do I need to create a temporary table to hold the business names/addresses
in a category so that I can then sort it?

Thanks,

Sid.

Sid Price Software Design

http://www.softtools.com



Reply via email to