envexlabs Posted November 7, 2008 Share Posted November 7, 2008 Hello, I have a directory, that is pulling from 2 tables, a simple directory 'table', and a more complex 'store' table. Right now, you can either choose to look at 1 table or the other. This is working fine. I would like the user to be able to just see a master list of both mixed into one list. I'm not sure if i can use join as i'm not trying to link up values from both tables, i would just like to grab all the info from both, sort by name and display to the user. Sorry if this is confusing, but does anyone have any ideas? Thanks, envex Quote Link to comment https://forums.phpfreaks.com/topic/131805-a-little-fuzzy-on-join/ Share on other sites More sharing options...
fenway Posted November 7, 2008 Share Posted November 7, 2008 I believe you're looking for UNION. Quote Link to comment https://forums.phpfreaks.com/topic/131805-a-little-fuzzy-on-join/#findComment-684694 Share on other sites More sharing options...
envexlabs Posted November 7, 2008 Author Share Posted November 7, 2008 thanks, i will look into this! *edit* I seem to be getting this error: The used SELECT statements have a different number of columns is there a way to grab the info even though the 2 tables are different in layout? Quote Link to comment https://forums.phpfreaks.com/topic/131805-a-little-fuzzy-on-join/#findComment-684700 Share on other sites More sharing options...
envexlabs Posted November 7, 2008 Author Share Posted November 7, 2008 After reading the gudilines post, i have additional info: CREATE TABLE `store` ( `id` int(100) NOT NULL auto_increment, `contact_name` varchar(250) NOT NULL, `username` varchar(200) NOT NULL, `name` varchar(500) NOT NULL, `email` varchar(500) NOT NULL, `password` varchar(40) NOT NULL, `slug` varchar(100) NOT NULL, `mem_type` int(1) NOT NULL, `pic` varchar(500) NOT NULL, `paid` varchar(1) NOT NULL default '0', `recur_date` date NOT NULL, `recur_type` int(1) NOT NULL, `description` text, `website` varchar(250) default NULL, UNIQUE KEY `id` (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=20 DEFAULT CHARSET=utf8 CREATE TABLE `directory_item` ( `id` int(100) NOT NULL auto_increment, `name` varchar(250) NOT NULL, `contact` varchar(300) NOT NULL, `email` varchar(300) NOT NULL, `website` varchar(200) default NULL, UNIQUE KEY `id` (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=388 DEFAULT CHARSET=utf8 mysql_query = SELECT * FROM `directory_item` UNION SELECT * FROM `store` GROUP BY `name` LIMIT 0,15' Quote Link to comment https://forums.phpfreaks.com/topic/131805-a-little-fuzzy-on-join/#findComment-684709 Share on other sites More sharing options...
envexlabs Posted November 7, 2008 Author Share Posted November 7, 2008 anyone? This is a tad bit urgent. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/131805-a-little-fuzzy-on-join/#findComment-684762 Share on other sites More sharing options...
Barand Posted November 7, 2008 Share Posted November 7, 2008 SELECT id, name, contact_name as contact, email, website FROM store UNION SELECT id, name, contact, email, website FROM directory ORDER BY name Quote Link to comment https://forums.phpfreaks.com/topic/131805-a-little-fuzzy-on-join/#findComment-684767 Share on other sites More sharing options...
envexlabs Posted November 7, 2008 Author Share Posted November 7, 2008 hey, so basically if it doesn't match both tables, i can't grab it? That's good enough though, i will try this out. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/131805-a-little-fuzzy-on-join/#findComment-684769 Share on other sites More sharing options...
Barand Posted November 7, 2008 Share Posted November 7, 2008 You can but you need to select "dummy" data from the other table to preserve the number of columns SELECT id, name, contact_name as contact, email, website, slug, recur_type FROM store UNION SELECT id, name, contact, email, website, '', 0 FROM directory ORDER BY name Quote Link to comment https://forums.phpfreaks.com/topic/131805-a-little-fuzzy-on-join/#findComment-684805 Share on other sites More sharing options...
fenway Posted November 8, 2008 Share Posted November 8, 2008 NULLs work too. Quote Link to comment https://forums.phpfreaks.com/topic/131805-a-little-fuzzy-on-join/#findComment-685113 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.