我正在尝试在drupal 8中对几个表进行完全外部联接...
mysql不支持完全外部联接,因此我使用左联接联合右联接
它获取了大多数数据,但是在我查询的材料中,我知道有多种材料,但是我只能得到一种...
我看不到我在做什么错
我直接访问数据库而不使用助手功能,因为这实际上是我正在编写的移动应用程序,用于从手机或平板电脑查询数据库
$query_phrase = "select
commerce_product_field_data.title as title,
commerce_product_field_data.product_id as product_id,
commerce_product__8fd244ef14.field_has_multiple_configuration_value as has_multiple_configuration,
commerce_product__field_barcode.field_barcode_value as barcode,
commerce_product__field_price.field_price_number as price,
commerce_product__field_price.field_price_currency_code as currency_code,
commerce_product__field_sku.field_sku_value as sku,
node_field_data.title as material_name,
file_managed.uri as uri,
file_managed.filename as filename
from {commerce_product_field_data}
left join commerce_product__8fd244ef14 on product_id = commerce_product__8fd244ef14.entity_id
left join commerce_product__field_barcode on product_id = commerce_product__field_barcode.entity_id
left join commerce_product__field_price on product_id = commerce_product__field_price.entity_id
left join commerce_product__field_sku on product_id = commerce_product__field_sku.entity_id
/*not working*/ left join commerce_product__field_materials on product_id = commerce_product__field_materials.entity_id
/*not working*/ left join node_field_data on commerce_product__field_materials.field_materials_target_id = node_field_data.nid
left join file_managed on product_id = file_managed.fid";
$query_phrase .= " union ";
$query_phrase .= "select
commerce_product_field_data.title as title,
commerce_product_field_data.product_id as product_id,
commerce_product__8fd244ef14.field_has_multiple_configuration_value as has_multiple_configuration,
commerce_product__field_barcode.field_barcode_value as barcode,
commerce_product__field_price.field_price_number as price,
commerce_product__field_price.field_price_currency_code as currency_code,
commerce_product__field_sku.field_sku_value as sku,
node_field_data.title as material_name,
file_managed.uri as uri,
file_managed.filename as filename
from {commerce_product_field_data}
right join commerce_product__8fd244ef14 on product_id = commerce_product__8fd244ef14.entity_id
right join commerce_product__field_barcode on product_id = commerce_product__field_barcode.entity_id
right join commerce_product__field_price on product_id = commerce_product__field_price.entity_id
right join commerce_product__field_sku on product_id = commerce_product__field_sku.entity_id
/*not working*/ right join commerce_product__field_materials on product_id = commerce_product__field_materials.entity_id
/*not working*/ right join node_field_data on commerce_product__field_materials.field_materials_target_id = node_field_data.nid
right join file_managed on product_id = file_managed.fid";
$query_phrase .= " where commerce_product__field_barcode.field_barcode_value = :barcode";
$query = db_query($query_phrase, array(":barcode" => "334242"));
当我调试结果时,我会得到
Array
(
[title] => Dummy Product
[product_id] => 2
[has_multiple_configuration] => 0
[barcode] => 334242
[price] => 325.000000
[currency_code] => USD
[sku] => dummy sku
[material_name] => test material
[uri] => public:a
但是我知道我有不止一种材料
答案 0 :(得分:1)
您在查询的Protein | Condition | Slope
A | N | 0.2
A | C | -0.5
B | N | 0.3
B | C | -0.4
部分中缺少where
子句。
left join