I have two tables that I want to query and merge based on a category_id.
My events table has a column called event_category_id that creates a relationship between the event and it’s category. The value is an int.
In my categories table I have a column called category_id which is what I want to match on and replace the int value with the varchar value of category_name.
What’s my syntax? Thanks for the help!
categories
CREATE TABLEwp_wild_dbem_categories(category_id
int(11) NOT NULL auto_increment,category_name
tinytext NOT NULL,category_id
PRIMARY KEY ()
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=latin1
events
CREATE TABLEwp_wild_dbem_events(event_id
mediumint(9) NOT NULL auto_increment,event_author
mediumint(9) default NULL,event_name
tinytext NOT NULL,event_start_time
time NOT NULL default '00:00:00',event_end_time
time NOT NULL default '00:00:00',event_start_date
date NOT NULL default '0000-00-00',event_end_date
date default NULL,event_notes
text,event_rsvp
tinyint(1) NOT NULL default '0',event_seats
tinyint(4) default NULL,event_contactperson_id
mediumint(9) default NULL,location_id
mediumint(9) NOT NULL default '0',recurrence_id
mediumint(9) default NULL,event_category_id
int(11) default NULL,event_id
UNIQUE KEY(event_id)
) ENGINE=MyISAM AUTO_INCREMENT=26 DEFAULT CHARSET=latin1
I don’t think you want a
UNION. You probably want something like this: