All pastes #18692 Raw Edit

Unnamed

public sql v1 · immutable
#18692 ·published 2005-07-28 08:37 UTC
rendered paste body
CREATE TABLE system_images (  image_id int(11) NOT NULL PRIMARY KEY auto_increment,  image_name varchar(100) default NULL,  image_descr text,  image_location varchar(255) default NULL,  image_thumnail varchar(255) default NULL) TYPE=INNODB;CREATE TABLE system_styles (  style_id int(11) NOT NULL PRIMARY KEY auto_increment,  style_name varchar(100) default NULL,  style_descr text,  style_location varchar(255) default NULL,  style_thumbnail varchar(255) default NULL,  style_image_prefix varchar(255) default NULL) TYPE=INNODB;CREATE TABLE system_obb_templates (  template_id int(11) NOT NULL PRIMARY KEY auto_increment,  template_name varchar(100) default NULL,  template_descr text,  template_location varchar(255) default NULL,  template_image varchar(255) default NULL,  visible enum('y','n') NOT NULL default 'y') TYPE=INNODB;CREATE TABLE system_templates_images (  temp_image_id int(11) NOT NULL PRIMARY KEY auto_increment,  template_id int(11) NOT NULL,  image_id int(11) NOT NULL,  KEY(template_id),  KEY(image_id),  FOREIGN KEY (template_id) REFERENCES system_obb_templates(template_id) ON DELETE CASCADE,  FOREIGN KEY (image_id) REFERENCES system_images(image_id) ON DELETE CASCADE) TYPE=INNODB;CREATE TABLE system_templates_styles (  template_style_id int(11) NOT NULL PRIMARY KEY auto_increment,  template_id int(11) NOT NULL default '0',  style_id int(11) NOT NULL default '0',  KEY(template_id),  KEY(style_id),  FOREIGN KEY (style_id) REFERENCES system_styles(style_id) ON DELETE CASCADE,  FOREIGN KEY (template_id) REFERENCES system_obb_templates(template_id) ON DELETE CASCADE) TYPE=INNODB;CREATE TABLE system_templates_defaults (	st_def_id int(11) NOT NULL PRIMARY KEY auto_increment,	template_image_id int(11) NOT NULL,	template_style_id int(11) NOT NULL,	KEY(template_image_id),	KEY(template_style_id),	FOREIGN KEY (template_image_id) REFERENCES system_templates_images(temp_image_id) ON DELETE CASCADE,	FOREIGN KEY (template_style_id) REFERENCES system_templates_styles(template_style_id) ON DELETE CASCADE) TYPE = INNODB;I use this query to get the image_id and the style_idSELECT sts.template_id, image_id FROM system_templates_defaults std LEFT JOIN system_templates_images sti ON std.template_image_id = sti.temp_image_id LEFT JOIN system_templates_styles sts ON std.template_style_id = sts.template_style_id WHERE sti.template_id = sts.template_id AND sts.template_id =1 ;