【发布时间】:2011-06-25 09:32:03
【问题描述】:
您好,感谢您查看我的问题,希望您能提供一些见解或方向。
我有三个表(基本上):“value_meta”、“value”和“values_visibility”。架构如下:
TABLE 'value_meta'
COMMENT: contains a list of different values, each referencing a different 'value' table
int id PK
tinyint value1 FK to value1.value
tinyint value2 FK to value2.value
tinyint value3 FK to value3.value
...
TABLE 'value'
COMMENT: there are different value tables (for example, if it were for user profile data, there would be a value table for "occupation", "body type", and/or "education level"
tinyint id PK
varchar(255) value
TABLE 'value_visibility'
COMMENT: one value visibility entry per value[n] in the 'value_meta' table, each a boolean value. If 1, the coding query will return the value as rerefenced in 'value[n]' table. if 0, return null
int id PK
BOOLEAN 'value1_visibility'
BOOLEAN 'value2_visibility'
BOOLEAN 'value3_visibility'
....
我想要做的是创建一个适当的 MySQL 查询来检查“对于 'value_meta' 中的每个 'value',如果 'value_visibility' 中的相应值条目为 1,则显示 value varchar。否则返回 null”。适当地,我想让它最有效(派生表与相关子查询、适当的条件和函数使用......我听说 ISNULL 很糟糕)。
我曾经擅长于在大学时直接从脑海中构建查询,但在多年不使用它之后,我已经变成了比扫帚还差三根稻草的人。谁能帮我?谢谢!
【问题讨论】:
-
你从哪里听说
ISNULL不好?
标签: mysql join performance conditional