omid020 Posted January 10, 2010 Share Posted January 10, 2010 I know that MySQL has restriction on creating views for those queries that have subqueries like my query but could you please help me to rewrite this query to resolve this issue ? SELECT leafCode , colorsCode , COALESCE(SUM(`INPUT`), 0) AS `INPUT` , COALESCE(SUM(`OUTPUT`), 0) AS `OUTPUT` , COALESCE(SUM(`INPUT`), 0) - COALESCE(SUM(`OUTPUT`), 0) AS `INVENTORY` FROM ( SELECT rs_leaves.leafCode , rs_colors.colorsCode , SUM(receipt_details.recAmount) AS `INPUT` , NULL AS `OUTPUT` FROM receipt_details INNER JOIN rs_leaves ON rs_leaves.leafID = receipt_details.leafName INNER JOIN rs_colors ON rs_colors.colorsID = receipt_details.leafColor GROUP BY rs_leaves.leafCode , rs_colors.colorsCode UNION ALL SELECT rs_leaves.leafCode , rs_colors.colorsCode , NULL AS `INPUT` , SUM(assign_details.assAmount) AS `OUTPUT` FROM assign_details INNER JOIN rs_leaves ON rs_leaves.leafID = assign_details.leafName INNER JOIN rs_colors ON rs_colors.colorsID = assign_details.leafColor GROUP BY rs_leaves.leafCode , rs_colors.colorsCode ) AS humpty GROUP BY leafCode , colorsCode Quote Link to comment https://forums.phpfreaks.com/topic/187919-i-need-to-create-view-but-my-query-has-one-subquery/ Share on other sites More sharing options...
fenway Posted January 16, 2010 Share Posted January 16, 2010 I can't even begin to make sense of that. Quote Link to comment https://forums.phpfreaks.com/topic/187919-i-need-to-create-view-but-my-query-has-one-subquery/#findComment-995944 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.