I m trying to get construct a sql statement where many to many relationship occurs. Basically i want to retrieve business based on 2 categories some business are included in both categories and queried through zip code. So far i got the zip code part but it doesnt distinguish the category and i don't have a table for the categories also what would be the most efficient way to do this?
here is sql statement so far
$query = "SELECT * FROM contacts WHERE zipcode in ( " . join(",", $zipcodes) . " ) ";
Here is the Table structures very simple. company_name
char(55) NOT NULL,
`phone` char(20) default NULL,
`email` char(40) default NULL,
`address` text,
`city` text,
`state` text,
`zipcode` varchar(5) default NULL,
`id` varchar(10) NOT NULL,
`geo_id` varchar(20) NOT NULL,
`website` varchar(40) NOT NULL,
`vendor_id` varchar(10) NOT NULL
`id` int(11) unsigned NOT NULL auto_increment,
`zip_code` varchar(5) character set utf8 collate utf8_bin NOT NULL,
`city` varchar(50) character set utf8 collate utf8_bin default NULL,
`county` varchar(50) character set utf8 collate utf8_bin default NULL,
`state_name` varchar(50) character set utf8 collate utf8_bin default NULL,
`state_prefix` varchar(2) character set utf8 collate utf8_bin default NULL,
`area_code` varchar(3) character set utf8 collate utf8_bin default NULL,
`time_zone` varchar(50) character set utf8 collate utf8_bin default NULL,
`lat` float NOT NULL,
`lon` float NOT NULL,
PRIMARY KEY (`id`),
KEY `zip_code` (`zip_code`)
I dont have the category table. I will make a table with 2 categories (retail and hospitality) only problem is how i can querry this table to determine if contact is in;
retail hospitality or both...