Howdy all!
I guess I'm a newbie, because I am stumped (or maybe just too durned
tired). Here's what I got...
CREATE TABLE `nodecat_map` (
`nodecat_id` mediumint(8) unsigned NOT NULL auto_increment,
`nodecat_cat_id ` mediumint(8) unsigned NOT NULL default '0',
`nodecat_node_i d` mediumint(8) unsigned NOT NULL default '0',
PRIMARY KEY (`nodecat_id`),
KEY `nodecat_cat_id ` (`nodecat_cat_i d`),
KEY `nodecat_node_i d` (`nodecat_node_ id`)
) TYPE=MyISAM;
CREATE TABLE `nodes` (
`node_id` mediumint(8) unsigned NOT NULL auto_increment,
`node_content_i d` mediumint(8) unsigned NOT NULL default '0',
PRIMARY KEY (`node_id`),
KEY `node_content_i d` (`node_content_ id`)
) TYPE=MyISAM;
CREATE TABLE `text` (
`text_id` mediumint(8) unsigned NOT NULL auto_increment,
`text_content_i d` mediumint(8) unsigned NOT NULL default '0',
`text_text` mediumtext NOT NULL default '',
`text_timestamp _dt` int(11) NOT NULL default '0',
PRIMARY KEY (`text_id`),
KEY `text_content_i d` (`text_content_ id`)
) TYPE=MyISAM;
Plus a 'CAT' table not shown, but referred to in NODECAT_MAP by
NODECAT_CAT_ID.
I don't want to spend too much time explaining how/why the tables are
organized like this, but here's a basic rundown of their
relationships:
1) NODECAT_MAP maps NODES to CATS (categories, basically folders),
with many NODES associated with a single CAT.
2) A NODE is basically a document whose content is stored in a TEXT
record, and in order to track multiple revisions of a NODE document
many TEXT records can be associated with a single NODE.
Here's what I CAN do ...
Given a CAT_ID (in this instance "5") I can successfully return all
records with the following query:
SELECT ncat.*, n.*, txt.*
FROM nodecat_map ncat
LEFT JOIN nodes n ON ncat.nodecat_no de_id=n.node_id
LEFT JOIN text txt ON n.node_content_ id=txt.text_con tent_id
WHERE ncat.nodecat_ca t_id=5
ORDER BY ncat.nodecat_id DESC, txt.text_timest amp_dt DESC ;
Here's what I WANT to do ...
First, the above query may return 3 NODES with 2 TEXT revisions each
for a total of 6 records. I only want it to return 3 records: the
most recent TEXT rec (based on the field text.text_times tamp_dt) for
each NODE.
I hope this makes sense. Thanks to anyone who can offer some
suggestions!
-Colman
I guess I'm a newbie, because I am stumped (or maybe just too durned
tired). Here's what I got...
CREATE TABLE `nodecat_map` (
`nodecat_id` mediumint(8) unsigned NOT NULL auto_increment,
`nodecat_cat_id ` mediumint(8) unsigned NOT NULL default '0',
`nodecat_node_i d` mediumint(8) unsigned NOT NULL default '0',
PRIMARY KEY (`nodecat_id`),
KEY `nodecat_cat_id ` (`nodecat_cat_i d`),
KEY `nodecat_node_i d` (`nodecat_node_ id`)
) TYPE=MyISAM;
CREATE TABLE `nodes` (
`node_id` mediumint(8) unsigned NOT NULL auto_increment,
`node_content_i d` mediumint(8) unsigned NOT NULL default '0',
PRIMARY KEY (`node_id`),
KEY `node_content_i d` (`node_content_ id`)
) TYPE=MyISAM;
CREATE TABLE `text` (
`text_id` mediumint(8) unsigned NOT NULL auto_increment,
`text_content_i d` mediumint(8) unsigned NOT NULL default '0',
`text_text` mediumtext NOT NULL default '',
`text_timestamp _dt` int(11) NOT NULL default '0',
PRIMARY KEY (`text_id`),
KEY `text_content_i d` (`text_content_ id`)
) TYPE=MyISAM;
Plus a 'CAT' table not shown, but referred to in NODECAT_MAP by
NODECAT_CAT_ID.
I don't want to spend too much time explaining how/why the tables are
organized like this, but here's a basic rundown of their
relationships:
1) NODECAT_MAP maps NODES to CATS (categories, basically folders),
with many NODES associated with a single CAT.
2) A NODE is basically a document whose content is stored in a TEXT
record, and in order to track multiple revisions of a NODE document
many TEXT records can be associated with a single NODE.
Here's what I CAN do ...
Given a CAT_ID (in this instance "5") I can successfully return all
records with the following query:
SELECT ncat.*, n.*, txt.*
FROM nodecat_map ncat
LEFT JOIN nodes n ON ncat.nodecat_no de_id=n.node_id
LEFT JOIN text txt ON n.node_content_ id=txt.text_con tent_id
WHERE ncat.nodecat_ca t_id=5
ORDER BY ncat.nodecat_id DESC, txt.text_timest amp_dt DESC ;
Here's what I WANT to do ...
First, the above query may return 3 NODES with 2 TEXT revisions each
for a total of 6 records. I only want it to return 3 records: the
most recent TEXT rec (based on the field text.text_times tamp_dt) for
each NODE.
I hope this makes sense. Thanks to anyone who can offer some
suggestions!
-Colman
Comment