funbinod Posted June 10, 2014 Share Posted June 10, 2014 i'm trying to union some tables but it is showing some errors here is what i wrote SELECT sum(amt) AS pamt FROM purchaseUNION SELECT sum(amt) AS samt FROM salesUNION SELECT sum(amt) AS ramt FROM receiptUNION SELECT sum(amt) AS ptamt FROM payment AS pt but it is selecting onle from first table (i.e. purchase) and for others it is saying "undefined index" Link to comment Share on other sites More sharing options...
justsomeguy Posted June 10, 2014 Share Posted June 10, 2014 All of the columns should have the same name. A union is a combination of the same sets, you're trying to combine 4 different sets. They should be the same. Link to comment Share on other sites More sharing options...
funbinod Posted June 10, 2014 Author Share Posted June 10, 2014 so what do u suggest me for this...... Link to comment Share on other sites More sharing options...
justsomeguy Posted June 10, 2014 Share Posted June 10, 2014 I suggest you make all of the columns the same name. Link to comment Share on other sites More sharing options...
funbinod Posted June 11, 2014 Author Share Posted June 11, 2014 then how can i distinguish the data to know which table is the result coming from? like purchase.amt or sales.amt or likewise...??? Link to comment Share on other sites More sharing options...
justsomeguy Posted June 11, 2014 Share Posted June 11, 2014 Add a second column with the table name. SELECT sum(amt) AS amt, 'purchase' as source_table FROM purchase... Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now