sql - Query attributes, where one attribute is missing -
i have question regarding query. there 2 tables:
objects table: ============== object id date 1 2016-03-15 2 2016-01-20 attributes table: ================= parent id attribute attributedata 1 size xl 2 size s 2 price 20 query join data this: ========================================== objet id size price 1 xl null 2 s 20 this: ========================================== objet id size price 2 s 20
a left join doesn't - because there no entry in attribute table price id1.
i sorry beein such newbie on this.
glad help.
steffen
i think conditional aggregation want:
select parentid, max(case when attribute = 'size' attributedata end) size, max(case when attribute = 'price' attributedata end) price attributes group parentid;
using left join
do:
select o.*, s.attributedata size, p.attributedata price objects o left join attributes s on o.objectid = s.parentid , s.attribute = 'size' left join attributes p on o.objectid = p.parentid , p.attribute = 'price';
note work, condition on attribute name needs in on
clause, not where
clause.
Comments
Post a Comment