MySQL MATCH AGAINST JOIN问题

时间:2017-07-19 15:44:25

标签: php mysql join pdo match-against

我正在制作用于公司记录管理的PHP + MySQL应用程序,我需要在每个表格中基于全文搜索的多个表格的联合结果。

查询是动态形成的,在最坏的情况下看起来是这样的:

SELECT `contracts_info`.`contract_number`, `contracts_info`.`balance`, `contracts_info`.`conclusion_date`, `contracts_info`.`activation_date`, `contracts_info`.`deactivation_date`,
`parents`.`mother_fullname`, `parents`.`mother_email`, `parents`.`mother_phone`, `parents`.`father_fullname`, `parents`.`father_email`, `parents`.`father_phone`, `parents`.`postal_office`,
`students`.`name`, `students`.`second_name`, `students`.`surname`, `students`.`form_number`, `students`.`form_letter`,
`students_info`.`medical_features`, `students_info`.`psychological_features`
FROM contracts_info
JOIN parents USING(contract_number)
JOIN students USING(contract_number)
JOIN students_info USING(contract_number)
WHERE MATCH (`contracts_info`.`contract_number`) AGAINST (? IN BOOLEAN MODE)
OR MATCH (`parents`.`contract_number`, `parents`.`mother_fullname`, `parents`.`mother_email`, `parents`.`father_fullname`, `parents`.`father_email`) AGAINST (? IN BOOLEAN MODE)
OR MATCH (`students`.`name`, `students`.`surname`, `students`.`contract_number`) AGAINST (? IN BOOLEAN MODE)
OR MATCH (`students_info`.`medical_features`, `students_info`.`psychological_features`, `students_info`.`contract_number`) AGAINST (? IN BOOLEAN MODE);

问题在于,当执行上述查询时,我从PDO类

中收到错误
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'contracts_info.contract_number' in 'where clause'

我尝试运行查询时是否包含在反引号中的查询,但这并没有任何区别。 没有JOINS的查询效果很好。我也调查了这些问题

mySQL MATCH across multiple tables

MySQL Optional LEFT JOIN With MATCH

但他们似乎没有相似的问题。 我不明白为什么会发生这种情况,因为我给出了列的确切名称,并且不使用AS别名。

那么为什么MySQL无法从现有表中查找和现有列?

MySQL version():5.6.29-76.2,PHP 5.5.9

提前谢谢。

编辑:

表定义:

CREATE TABLE IF NOT EXISTS `contracts_info` (
  `contract_number` varchar(11) COLLATE utf8_unicode_ci NOT NULL,
  `balance` decimal(7,2) unsigned zerofill NOT NULL,
  `conclusion_date` date NOT NULL,
  `activation_date` date NOT NULL,
  `deactivation_date` date NOT NULL,
  PRIMARY KEY (`contract_number`),
  FULLTEXT KEY `contract_number` (`contract_number`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

CREATE TABLE IF NOT EXISTS `students` (
    `contract_number` varchar(11) COLLATE utf8_unicode_ci NOT NULL,
    `name` varchar(25) COLLATE utf8_unicode_ci NOT NULL,
    `second_name` varchar(25) COLLATE utf8_unicode_ci NOT NULL,
    `surname` varchar(25) COLLATE utf8_unicode_ci NOT NULL,
    `form_number` enum('1','2','3','4','5','6','7','8','9','10','11','12') COLLATE utf8_unicode_ci NOT NULL,
    `form_letter` enum('А','Б','В','Г','Д') COLLATE utf8_unicode_ci NOT NULL,
    PRIMARY KEY (`contract_number`),
    FULLTEXT KEY `name` (`name`),
    FULLTEXT KEY `surname` (`surname`),
    FULLTEXT KEY `contract_number` (`contract_number`)
  ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

CREATE TABLE IF NOT EXISTS `students_info` (
  `contract_number` varchar(11) COLLATE utf8_unicode_ci NOT NULL,
  `medical_features` text COLLATE utf8_unicode_ci NOT NULL,
  `psychological_features` text COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`contract_number`),
  FULLTEXT KEY `medical_features` (`medical_features`),
  FULLTEXT KEY `psycological_features` (`psychological_features`),
  FULLTEXT KEY `contract_number` (`contract_number`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

CREATE TABLE IF NOT EXISTS `parents` (
  `contract_number` varchar(11) COLLATE utf8_unicode_ci NOT NULL,
  `mother_fullname` varchar(90) COLLATE utf8_unicode_ci NOT NULL,
  `mother_email` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
  `mother_phone` decimal(15,0) NOT NULL,
  `father_fullname` varchar(90) COLLATE utf8_unicode_ci NOT NULL,
  `father_email` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
  `father_phone` decimal(15,0) NOT NULL,
  `postal_office` int(4) NOT NULL,
  PRIMARY KEY (`contract_number`),
  FULLTEXT KEY `contract_number` (`contract_number`),
  FULLTEXT KEY `mother_fullname` (`mother_fullname`),
  FULLTEXT KEY `mother_email` (`mother_email`),
  FULLTEXT KEY `father_fullname` (`father_fullname`),
  FULLTEXT KEY `father_email` (`father_email`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

0 个答案:

没有答案