Monday, December 10, 2012

MySQL Query With Multiple Left Join

Here is a query I used to (LEFT) join multiple tables:

SELECT 
fe.fex_uid, 
fe.ca_id,
fet.product_group_id, 
pg.name,
fet.type, 
fet.value, 
q.weight,
DATE_FORMAT( fe.timestamp,  '%Y-%m-%d' ) as fe_date

FROM 
field_executions fe
     LEFT JOIN field_execution_items fet
          ON fe.fex_uid = fet.fex_uid
     LEFT JOIN qualifiers q
          ON fet.value = q.id
     LEFT JOIN product_groups pg
          ON fet.product_group_id = pg.id

WHERE 
fe.company_id = '000002' AND
fe.ca_id = 3 AND
date_format(fe.timestamp,'%Y-%m-%d') LIKE '2012-12%'

ORDER BY 
fe.fex_uid,
fet.product_group_id

No comments:

Post a Comment

Powered by Blogger.