如何从 mysql 连接接收 1 行而不是 4 行
How to receive 1 row from a mysql join instead of 4
SELECT
pe.entity_id,
pev.attribute_id,
pev.entity_id,
if(pev.attribute_id='134', pev.value, null) as garantie,
if(pev.attribute_id='97', pev.value, null) as url,
if(pev.attribute_id='71', pev.value, null) as nume,
if(pev.attribute_id='85', pev.value, null) as poza
FROM
mg_catalog_product_entity pe,
mg_catalog_product_entity_varchar pev
WHERE
pev.entity_id=pe.entity_id and
(pev.attribute_id='134' or pev.attribute_id='97' or pev.attribute_id='71' or pev.attribute_id='85')
我有这个 mysql 加入那个 returns 4 行,像这样:
value1 null null null
null value2 null null
null null value3 null
null null null value4
我必须做什么才能像这样只收到一行?
value1 value2 value3 value4
SELECT
pe.entity_id,
max(if(pev.attribute_id='134', pev.value, null)) as garantie,
max(if(pev.attribute_id='97', pev.value, null)) as url,
max(if(pev.attribute_id='71', pev.value, null)) as nume,
max(if(pev.attribute_id='85', pev.value, null)) as poza
FROM
mg_catalog_product_entity pe
JOIN
mg_catalog_product_entity_varchar pev
ON
pev.entity_id = pe.entity_id
WHERE
pev.attribute_id in (134,97,71,85)
GROUP BY
pe.entity_id
SELECT
pe.entity_id,
pev.attribute_id,
pev.entity_id,
if(pev.attribute_id='134', pev.value, null) as garantie,
if(pev.attribute_id='97', pev.value, null) as url,
if(pev.attribute_id='71', pev.value, null) as nume,
if(pev.attribute_id='85', pev.value, null) as poza
FROM
mg_catalog_product_entity pe,
mg_catalog_product_entity_varchar pev
WHERE
pev.entity_id=pe.entity_id and
(pev.attribute_id='134' or pev.attribute_id='97' or pev.attribute_id='71' or pev.attribute_id='85')
我有这个 mysql 加入那个 returns 4 行,像这样:
value1 null null null
null value2 null null
null null value3 null
null null null value4
我必须做什么才能像这样只收到一行?
value1 value2 value3 value4
SELECT
pe.entity_id,
max(if(pev.attribute_id='134', pev.value, null)) as garantie,
max(if(pev.attribute_id='97', pev.value, null)) as url,
max(if(pev.attribute_id='71', pev.value, null)) as nume,
max(if(pev.attribute_id='85', pev.value, null)) as poza
FROM
mg_catalog_product_entity pe
JOIN
mg_catalog_product_entity_varchar pev
ON
pev.entity_id = pe.entity_id
WHERE
pev.attribute_id in (134,97,71,85)
GROUP BY
pe.entity_id