Create UNION SQL

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
ach8
User
Posts: 174

Create UNION SQL

Post by ach8 »

How to solution show result this sql on PHPMaker ?

SELECT x.FieldA, x.FieldB, x.FieldC, x.FieldD FROM (
SELECT 'Penerimaan' AS FieldA, FieldB, FieldC, SUM(FieldX) AS FieldC FROM t1 GROUP BY FieldB, FieldC
UNION
SELECT 'Pengeluaran' AS FieldA, FieldB, FieldC, SUM(FieldX) AS FieldC FROM t2 GROUP BY FieldB, FieldC
) x
ORDER BY FieldB, FieldC


scs
User
Posts: 694

Post by scs »

Create VIEW, then use the VIEW to present the result.


ach8
User
Posts: 174

Post by ach8 »

ERROR : View's SELECT contains a subquery in the FROM clause


mobhar
User
Posts: 11737

Post by mobhar »

To solve the issue, try to make two separated Database Views, afterwards make a new Database View which contains the relationship between those two Database Views.


ach8
User
Posts: 174

Post by ach8 »

I have try about make a new database view, but i confuse how to display like my query to relationship between those two my database views?


mobhar
User
Posts: 11737

Post by mobhar »

Try this Database View:

SELECT 'Penerimaan' AS FieldA, FieldB, FieldC, SUM(FieldX) AS FieldC FROM t1 GROUP BY FieldB, FieldC
UNION
SELECT 'Pengeluaran' AS FieldA, FieldB, FieldC, SUM(FieldX) AS FieldC FROM t2 GROUP BY FieldB, FieldC


Post Reply