在MySQL中等于不返回行,在where子句中什么都不替换

时间:2016-11-08 03:08:59

标签: php mysql drupal

简短摘要:在Drupal环境中运行,我有一个查询,它返回一个空结果集,除非我对内部选择的结果运行某种命令。这可以是Trim,replace,upper。

所有不需要的字段都已从select中删除,因此我只剩下查询的相关部分。

mysql> SELECT HEX(taxonomy_term_field_data_node_field_data.name)  
   FROM node_field_data 
   LEFT JOIN (SELECT td.*, tn.nid AS nid 
              FROM taxonomy_term_field_data td
              LEFT JOIN taxonomy_index tn ON tn.tid = td.tid
              WHERE (td.vid IN ('category'))
             ) taxonomy_term_field_data_node_field_data
   ON node_field_data.nid = taxonomy_term_field_data_node_field_data.nid  
   WHERE (taxonomy_term_field_data_node_field_data.name = "Politik");
Empty set (0.01 sec)

taxonomy_term_field_data表不在联接中时(其中名称=" Politik")可以从mysql> SELECT name FROM taxonomy_term_field_data WHERE name = "Politik"; +---------+ | name | +---------+ | Politik | +---------+ 1 row in set (0.00 sec) 表中进行选择?

mysql> SELECT HEX(taxonomy_term_field_data_node_field_data.name) 
       FROM node_field_data 
       LEFT JOIN (SELECT td.*, tn.nid AS nid
                  FROM taxonomy_term_field_data td
                  LEFT JOIN taxonomy_index tn ON tn.tid = td.tid 
                  WHERE (td.vid IN  ('category'))
                 ) taxonomy_term_field_data_node_field_data
       ON node_field_data.nid = taxonomy_term_field_data_node_field_data.nid  
       WHERE (REPLACE(taxonomy_term_field_data_node_field_data.name, "", "") = "Politik");
+----------------------------------------------------+
| HEX(taxonomy_term_field_data_node_field_data.name) |
+----------------------------------------------------+
| 506F6C6974696B                                     |
| 506F6C6974696B                                     |
| 506F6C6974696B                                     |
+----------------------------------------------------+
3 rows in set (0.01 sec)

如果我在查询中没有替换任何内容,我会得到结果: 这也可以在字符串或TRIM上使用UPPER。

taxonomy_term_field_data table

我还尝试在mysql> explain SELECT taxonomy_term_field_data_node_field_data.name FROM node_field_data LEFT JOIN (SELECT td.*, tn.nid AS nid FROM taxonomy_term_field_data td LEFT JOIN taxonomy_index tn ON tn.tid = td.tid WHERE (td.vid IN ('category')) ) taxonomy_term_field_data_node_field_data ON node_field_data.nid = taxonomy_term_field_data_node_field_data.nid WHERE (trim(taxonomy_term_field_data_node_field_data.name) = "Politik"); +----+-------------+-----------------+-------+----------------------------------------------+-------------+---------+--------------------------+------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-----------------+-------+----------------------------------------------+-------------+---------+--------------------------+------+-------------+ | 1 | PRIMARY | node_field_data | index | PRIMARY,node__id__default_langcode__langcode | node__vid | 4 | NULL | 20 | Using index | | 1 | PRIMARY | <derived2> | ref | <auto_key0> | <auto_key0> | 5 | v15x.node_field_data.nid | 14 | Using where | | 2 | DERIVED | td | ALL | taxonomy_term__tree,taxonomy_term__vid_name | NULL | NULL | NULL | 1404 | Using where | | 2 | DERIVED | tn | ref | term_node | term_node | 4 | v15x.td.tid | 1 | Using index | +----+-------------+-----------------+-------+----------------------------------------------+-------------+---------+--------------------------+------+-------------+ 4 rows in set (0.00 sec) mysql> explain SELECT taxonomy_term_field_data_node_field_data.name FROM node_field_data LEFT JOIN (SELECT td.*, tn.nid AS nid FROM taxonomy_term_field_data td LEFT JOIN taxonomy_index tn ON tn.tid = td.tid WHERE (td.vid IN ('category')) ) taxonomy_term_field_data_node_field_data ON node_field_data.nid = taxonomy_term_field_data_node_field_data.nid WHERE (taxonomy_term_field_data_node_field_data.name = "Politik"); +----+-------------+-----------------+-------+----------------------------------------------+-------------+---------+--------------------------+------+-----------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-----------------+-------+----------------------------------------------+-------------+---------+--------------------------+------+-----------------------+ | 1 | PRIMARY | node_field_data | index | PRIMARY,node__id__default_langcode__langcode | node__vid | 4 | NULL | 20 | Using index | | 1 | PRIMARY | <derived2> | ref | <auto_key1> | <auto_key1> | 5 | v15x.node_field_data.nid | 14 | Using index condition | | 2 | DERIVED | td | ALL | taxonomy_term__tree,taxonomy_term__vid_name | NULL | NULL | NULL | 1404 | Using where | | 2 | DERIVED | tn | ref | term_node | term_node | 4 | v15x.td.tid | 1 | Using index | +----+-------------+-----------------+-------+----------------------------------------------+-------------+---------+--------------------------+------+-----------------------+ 4 rows in set (0.00 sec) 中更新名称=修剪(名称),但这不起作用。

其中一个查询使用where和另一个条件索引,但是如何解决这个问题的任何输入都非常受欢迎。

TABLE <<page-expression,> row-expression,>column-expression </ table-option(s)>;

0 个答案:

没有答案