-- phpMyAdmin SQL Dump -- version 2.9.1.1-Debian-4 -- http://www.phpmyadmin.net -- -- Host: localhost -- Generation Time: Nov 06, 2008 at 06:30 PM -- Server version: 5.0.18 -- PHP Version: 5.2.0 SET FOREIGN_KEY_CHECKS=0; -- -- Database: `recip` -- -- -------------------------------------------------------- -- -- Table structure for table `datatable` -- DROP TABLE IF EXISTS `datatable`; CREATE TABLE `datatable` ( `data_id` int(11) NOT NULL auto_increment, `parameter_definition_id` varchar(30) collate utf8_unicode_ci NOT NULL, `value_definition_id` varchar(30) collate utf8_unicode_ci default NULL, PRIMARY KEY (`data_id`), KEY `parameter_definition_id` (`parameter_definition_id`), KEY `value_definition_id` (`value_definition_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1737 ; -- -- Dumping data for table `datatable` -- INSERT INTO `datatable` (`data_id`, `parameter_definition_id`, `value_definition_id`) VALUES (481, 'sessStatus1', 'asStatusCompleted'), (483, 'analFamiliarity1', 'none'), (484, 'acFamiliarity1', 'native'), (485, 'acGrammar1', 'traditional'), (625, 'sessType1', 'sTypeAssisted'), (629, 'acGender1', 'female'), (1487, 'langSample1', 'geneticWALS'), (1488, 'langSample1', 'arealGenera'), (1489, 'langSample1', 'arealLanguage'), (1736, 'ansLangRating1', 'rateGood'); -- -------------------------------------------------------- -- -- Table structure for table `parameterDefinition` -- DROP TABLE IF EXISTS `parameterDefinition`; CREATE TABLE `parameterDefinition` ( `parameter_id` varchar(30) collate utf8_unicode_ci NOT NULL, `data_type` varchar(20) collate utf8_unicode_ci NOT NULL, `parameter_value_type_id` varchar(30) collate utf8_unicode_ci default NULL, PRIMARY KEY (`parameter_id`), KEY `parameter_value_type_id` (`parameter_value_type_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -- -- Dumping data for table `parameterDefinition` -- INSERT INTO `parameterDefinition` (`parameter_id`, `data_type`, `parameter_value_type_id`) VALUES ('acFamiliarity1', 'enum', 'Familiarity'), ('acGender1', 'enum', 'personGender'), ('acGrammar1', 'enum', 'grammarFamiliarity'), ('analFamiliarity1', 'enum', 'Familiarity'), ('ansLangRating1', 'enum', 'langRating'), ('langSample1', 'enum', 'LangSample'), ('sessStatus1', 'enum', 'sessStatus'), ('sessType1', 'enum', 'sessionType'); -- -------------------------------------------------------- -- -- Table structure for table `valueDefinition` -- DROP TABLE IF EXISTS `valueDefinition`; CREATE TABLE `valueDefinition` ( `value_id` varchar(30) collate utf8_unicode_ci NOT NULL, `value_label` text collate utf8_unicode_ci NOT NULL, `value_type_id` varchar(30) collate utf8_unicode_ci NOT NULL, PRIMARY KEY (`value_id`,`value_type_id`), KEY `value_type_id` (`value_type_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -- -- Dumping data for table `valueDefinition` -- INSERT INTO `valueDefinition` (`value_id`, `value_label`, `value_type_id`) VALUES ('Africa', 'Africa', 'lingArea'), ('arealGenera', 'Areal-Genera-50', 'LangSample'), ('arealLanguage', 'Areal-Language-50', 'LangSample'), ('arealSurface', 'Areal-Surface-50', 'LangSample'), ('asStatusCompleted', 'Completed', 'sessStatus'), ('asStatusEditing', 'Needs review/editing', 'sessStatus'), ('asStatusInactive', 'Inactive', 'sessStatus'), ('asStatusOngoing', 'Ongoing collection', 'sessStatus'), ('asStatusStarted', 'Started', 'sessStatus'), ('asStatusStub', 'Stub', 'sessStatus'), ('Australia', 'Australia and New Guinea', 'lingArea'), ('case', 'case', 'AgrFeature'), ('definiteness', 'definiteness', 'AgrFeature'), ('Eurasia', 'Eurasia', 'lingArea'), ('female', 'female', 'personGender'), ('fluent', 'very well (fluent)', 'Familiarity'), ('gender', 'gender/noun class', 'AgrFeature'), ('geneticWALS', 'Genetic-WALS', 'LangSample'), ('informal', 'as speaker only, no formal knowledge', 'grammarFamiliarity'), ('limited', 'limited communication skills', 'Familiarity'), ('male', 'male', 'personGender'), ('native', 'native speaker', 'Familiarity'), ('nearNative', 'near-native command', 'Familiarity'), ('no', 'no', 'boolean'), ('none', 'no knowledge of the language', 'Familiarity'), ('NorthAmerica', 'North America', 'lingArea'), ('notapplicable', 'Does not apply', 'Missing'), ('notsure', 'Not sure', 'Missing'), ('number', 'number', 'AgrFeature'), ('person', 'person', 'AgrFeature'), ('rateGood', 'Good', 'langRating'), ('rateLimited', 'Useful but limited', 'langRating'), ('rateSatisfactory', 'Satisfactory', 'langRating'), ('SE-Asia', 'SE Asia and Oceania', 'lingArea'), ('SouthAmerica', 'South America', 'lingArea'), ('sTypeAssisted', 'Consultant-analyst, plus a second analyst', 'sessionType'), ('stypeSingle', 'Single consultant-analyst', 'sessionType'), ('stypeWithConsultant', 'Analyst working with a consultant', 'sessionType'), ('stypeWritten', 'Based on written sources only', 'sessionType'), ('thorough', 'specialized knowledge, e.g., as language teacher or linguist', 'grammarFamiliarity'), ('traditional', 'was taught traditional grammar in school', 'grammarFamiliarity'), ('yes', 'yes', 'boolean'); -- -------------------------------------------------------- -- -- Table structure for table `valueType` -- DROP TABLE IF EXISTS `valueType`; CREATE TABLE `valueType` ( `type_id` varchar(30) collate utf8_unicode_ci NOT NULL, `type_label` text collate utf8_unicode_ci NOT NULL, PRIMARY KEY (`type_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -- -- Dumping data for table `valueType` -- INSERT INTO `valueType` (`type_id`, `type_label`) VALUES ('AgrFeature', 'Agreement category'), ('boolean', 'Boolean'), ('Familiarity', 'Familiarity'), ('grammarFamiliarity', 'Familiarity with the Grammar'), ('langRating', 'Rating of the dataset'), ('LangSample', 'Balanced Sample'), ('lingArea', 'Macro-area (after WALS)'), ('Missing', 'Missing values'), ('personGender', 'Gender (of a person)'), ('sessionType', 'Session type'), ('sessStatus', 'Session status'); -- -- Constraints for dumped tables -- -- -- Constraints for table `datatable` -- ALTER TABLE `datatable` ADD CONSTRAINT `data_ibfk_2` FOREIGN KEY (`parameter_definition_id`) REFERENCES `parameterDefinition` (`parameter_id`) ON DELETE CASCADE ON UPDATE CASCADE, ADD CONSTRAINT `data_ibfk_3` FOREIGN KEY (`value_definition_id`) REFERENCES `valueDefinition` (`value_id`) ON DELETE CASCADE ON UPDATE CASCADE; -- -- Constraints for table `parameterDefinition` -- ALTER TABLE `parameterDefinition` ADD CONSTRAINT `parameterDefinition_ibfk_3` FOREIGN KEY (`parameter_value_type_id`) REFERENCES `valueType` (`type_id`) ON UPDATE CASCADE; -- -- Constraints for table `valueDefinition` -- ALTER TABLE `valueDefinition` ADD CONSTRAINT `valueDefinition_ibfk_2` FOREIGN KEY (`value_type_id`) REFERENCES `valueType` (`type_id`) ON DELETE CASCADE ON UPDATE CASCADE; SET FOREIGN_KEY_CHECKS=1; -- And here is the weird behaviour: -- -- This returns one row for each row of d, as it should -- (there are matching keys for everything) SELECT * FROM datatable d INNER JOIN parameterDefinition p ON d.parameter_definition_id = p.parameter_id INNER JOIN valueDefinition v ON ( (d.value_definition_id = v.value_id) AND ( (v.value_type_id = p.parameter_value_type_id) -- The culprit: OR (v.value_type_id = 'Missing') ) ) \G -- This returns nothing! SELECT * FROM (datatable d INNER JOIN parameterDefinition p ON d.parameter_definition_id = p.parameter_id) INNER JOIN valueDefinition v ON ( (d.value_definition_id = v.value_id) AND ( (v.value_type_id = p.parameter_value_type_id) OR (v.value_type_id = 'Missing') ) ) \G