SELECT `c`.`contact_id`, `c`.`first_name`, `c`.`last_name`, `c`.`email_address`, `c`.`city`, `c`.`rating`, `c`.`date_created`, `cej`.`assigned_dt` FROM `contacts` `c` LEFT JOIN `contact_employee_join` `cej` ON `c`.`contact_id` = `cej`.`contact_id` LEFT JOIN `employee_locations` `el` ON `cej`.`employee_id` = `el`.`employee_id` LEFT JOIN `contact_notes` `cn` ON `c`.`contact_id` = `cn`.`contact_id` LEFT JOIN `contact_communications` `cc` ON `c`.`contact_id` = `cc`.`contact_id` WHERE (`c`.`first_name` LIKE '%$term%' || `c`.`last_name` LIKE '%$term%' || `c`.`address1` LIKE '%$term%' || `c`.`address2` LIKE '%$term%' || `c`.`city` LIKE '%$term%' || `cn`.`note` LIKE '%$term%' || `cc`.`notes` LIKE '%$term%') && (`c`.`rating` = '$rating') && ($date_field BETWEEN '$date_from' AND '$date_to') && (`cej`.`employee_id` = '$employee_id') ORDER BY `c`.`last_name`, `c`.`first_name` ASC
CREATE TABLE `contacts` (
`contact_id` int(11) NOT NULL AUTO_INCREMENT,
`first_name` varchar(32) NOT NULL,
`last_name` varchar(32) NOT NULL,
`address1` varchar(32) NOT NULL,
`address2` varchar(32) NOT NULL,
`city` varchar(64) NOT NULL,
`province` varchar(2) NOT NULL,
`country` varchar(2) NOT NULL,
`postal_code` varchar(12) NOT NULL,
`home_phone` varchar(12) NOT NULL,
`cell_phone` varchar(12) NOT NULL,
`work_phone` varchar(12) NOT NULL,
`work_phone_ext` varchar(6) NOT NULL,
`fax` varchar(12) NOT NULL,
`email_address` varchar(64) NOT NULL,
`password` varchar(64) NOT NULL,
`notes` text NOT NULL,
`subscribed` enum('No','Yes') NOT NULL DEFAULT 'No',
`contact_source` varchar(32) DEFAULT NULL,
`rating` varchar(12) NOT NULL,
`location_id` mediumint(9) NOT NULL,
`date_created` date NOT NULL,
PRIMARY KEY (`contact_id`),
KEY `last_name` (`last_name`),
KEY `first_name` (`first_name`),
KEY `last_first` (`last_name`,`first_name`)
) ENGINE=MyISAM AUTO_INCREMENT=4321 DEFAULT CHARSET=utf8
CREATE TABLE `contact_communications` (
`log_id` int(11) NOT NULL AUTO_INCREMENT,
`contact_id` int(11) NOT NULL,
`employee_id` int(11) NOT NULL,
`type` varchar(32) NOT NULL,
`direction` varchar(32) NOT NULL,
`date` date NOT NULL,
`time` time NOT NULL,
`notes` text NOT NULL,
PRIMARY KEY (`log_id`)
) ENGINE=MyISAM AUTO_INCREMENT=5155 DEFAULT CHARSET=utf8
CREATE TABLE `contact_notes` (
`note_id` int(11) NOT NULL AUTO_INCREMENT,
`contact_id` int(11) DEFAULT NULL,
`note` text,
`added_by` varchar(64) DEFAULT NULL,
`added_dt` datetime DEFAULT NULL,
PRIMARY KEY (`note_id`)
) ENGINE=MyISAM AUTO_INCREMENT=995 DEFAULT CHARSET=utf8
CREATE TABLE `contact_custom_data` (
`contact_id` int(11) NOT NULL DEFAULT '0',
`custom_field_id` int(11) NOT NULL DEFAULT '0',
`value` varchar(255) DEFAULT NULL,
PRIMARY KEY (`contact_id`,`custom_field_id`),
KEY `contact_id` (`contact_id`),
KEY `custom_field_id` (`custom_field_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
CREATE TABLE `contact_employee_join` (
`contact_id` int(11) NOT NULL,
`employee_id` int(11) NOT NULL,
`assigned_by` varchar(64) NOT NULL,
`assigned_dt` datetime NOT NULL,
PRIMARY KEY (`contact_id`,`employee_id`),
KEY `contact_id` (`contact_id`),
KEY `employee_id` (`employee_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
CREATE TABLE `employee_locations` (
`employee_id` int(11) NOT NULL,
`location_id` int(11) NOT NULL,
PRIMARY KEY (`employee_id`,`location_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8| Subject | Written By | Posted |
|---|---|---|
| Complex search - multiple fields and tables - need advice. | Luke Pittman | 04/17/2012 04:49PM |
| Re: Complex search - multiple fields and tables - need advice. | laptop alias | 04/18/2012 05:05AM |
| Re: Complex search - multiple fields and tables - need advice. | Luke Pittman | 04/18/2012 10:31AM |
| Re: Complex search - multiple fields and tables - need advice. | Luke Pittman | 04/18/2012 11:19AM |
| Re: Complex search - multiple fields and tables - need advice. | Luke Pittman | 04/18/2012 11:24AM |
| Re: Complex search - multiple fields and tables - need advice. | laptop alias | 04/18/2012 05:32PM |
| Re: Complex search - multiple fields and tables - need advice. | Luke Pittman | 04/19/2012 12:43PM |
| Re: Complex search - multiple fields and tables - need advice. | laptop alias | 04/19/2012 01:11PM |
| Re: Complex search - multiple fields and tables - need advice. | Luke Pittman | 04/19/2012 01:15PM |
Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.