Created
August 1, 2010 17:03
-
-
Save onlymejosh/503537 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT candidates.*, histories.job_title, institutions.name FROM `candidates` | |
JOIN histories ON (histories.candidate_id = candidates.id AND histories.finish_date IS NULL) | |
JOIN institutions ON histories.institution_id = institutions.id | |
WHERE (candidates.id IN ('1','3','4','6') ) | |
ORDER BY institutions.name ASC, candidates.last_name ASC | |
CREATE TABLE `candidates` ( | |
`id` int(11) NOT NULL AUTO_INCREMENT, | |
`first_name` varchar(255) DEFAULT NULL, | |
`last_name` varchar(255) DEFAULT NULL, | |
PRIMARY KEY (`id`) | |
) ENGINE=MyISAM DEFAULT CHARSET=latin1 | |
CREATE TABLE `histories` ( | |
`id` int(11) NOT NULL AUTO_INCREMENT, | |
`job_title` varchar(255) DEFAULT NULL, | |
`candidate_id` int(11) DEFAULT NULL, | |
`institution_id` int(11) DEFAULT NULL, | |
`start_date` date DEFAULT NULL, | |
`finish_date` date DEFAULT NULL, | |
PRIMARY KEY (`id`) | |
) ENGINE=MyISAM DEFAULT CHARSET=latin1 | |
CREATE TABLE `institutions` ( | |
`id` int(11) NOT NULL AUTO_INCREMENT, | |
`name` varchar(255) DEFAULT NULL, | |
PRIMARY KEY (`id`) | |
) ENGINE=MyISAM DEFAULT CHARSET=latin1 | |
I want the data to look either like: | |
Candidate.*, Institutions.name | |
WHERE histories.finish_date = NULL | |
or | |
Candidate.*, Institution NULL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment