Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Union Query in MYSQL 1

Status
Not open for further replies.

sOlsTiCezA

Programmer
Mar 20, 2002
17
ZA
Hi

How do i perform a union select in MYSQL. I am currently using ver 3.23.45 which does not support the union statement.

Thanks
 
Hi,

i'm using version 3.23.49
since UNION is only supported in version 4, is there any other way that i can implement query with UNION syntax? Thanx alot!!
 
Are you wanting to do a JOIN?
Here's a query I use. I store the style sheets from my site in MySQL, and make it possible to have only the styles require for each page loaded, and a user selectable theme.

The tables:
Code:
CREATE TABLE site_style_code (
  code_id tinyint(3) unsigned NOT NULL auto_increment,
  name varchar(16) NOT NULL default '',
  description text NOT NULL,
  styles text NOT NULL,
  PRIMARY KEY  (code_id),
  UNIQUE KEY name (name)
) TYPE=MyISAM;

CREATE TABLE site_style_themes (
  theme_id tinyint(3) unsigned NOT NULL auto_increment,
  name varchar(16) NOT NULL default '',
  PRIMARY KEY  (theme_id),
  UNIQUE KEY name (name)
) TYPE=MyISAM;

CREATE TABLE site_style_types (
  type_id tinyint(3) unsigned NOT NULL auto_increment,
  name varchar(16) NOT NULL default '',
  PRIMARY KEY  (type_id),
  UNIQUE KEY name (name)
) TYPE=MyISAM;

CREATE TABLE site_styles (
  id tinyint(3) unsigned NOT NULL auto_increment,
  code_id tinyint(3) unsigned NOT NULL default '0',
  type_id tinyint(3) unsigned NOT NULL default '0',
  theme_id tinyint(3) unsigned NOT NULL default '0',
  PRIMARY KEY  (id),
  UNIQUE KEY relation (code_id,type_id,theme_id),
  KEY code_id (code_id),
  KEY type_id (type_id),
  KEY theme_id (theme_id)
) TYPE=MyISAM;

I query each type separately:
Code:
SELECT code.styles FROM site_styles style
 LEFT JOIN site_style_themes theme ON (style.theme_id = theme.theme_id)
 LEFT JOIN site_style_code code ON (style.code_id = code.code_id)
 LEFT JOIN site_style_types type ON (style.type_id = type.type_id)
 WHERE theme.name = 'theme_name' AND type.name = 'type_name';
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top