Re: modeling either/or relationship...

From: David Portas <REMOVE_BEFORE_REPLYING_dportas_at_acm.org>
Date: 1 Feb 2006 01:55:45 -0800
Message-ID: <1138787745.277736.181900_at_g14g2000cwa.googlegroups.com>


jason.glumidge_at_gmail.com wrote:

>
> The only thing that strikes me with the hierarchical class structure as
> posted by Celko is that I am not clear about how I would go about
> querying it (but perhaps this is due to limitations in my SQL skills).
>
> Perhaps someone in the now could put me on the right track - If I did
> want to know (for example) how many 4-door cars there were in the
> system my impression is that I would not be able to extract this
> information this in a single SQ: query (I would insted use some sort of
> external script processing to process query results before firing off
> new ones), as somehow I will have to be matching entries in the Vehicle
> table (e.g. the Char(3) SUV) to other actual table names, before I
> query those tables to count their rows?

I think the different tables for 2- and 4-door vehicles was a poorly chosen example - useful only to illustrate how to extend the design. The number of doors is an attribute that all vehicles have in common so it more sensibly belongs in one place only - the Vehicles table.

More generally, a union and joins should allow you to interrogate the data across all tables without resorting to procedural code in an external script.

-- 
David Portas
Received on Wed Feb 01 2006 - 10:55:45 CET

Original text of this message