0

I have three activities in my application with following names:
Activity #1
Activity #2
Activity Final

Also for each activity, I have a table with following names:
Table #1
Table #2
Table Final

Default value of Qty column is "0" and users will change it at run-time.

I've created Table#1 and Table#2 and they work fine.

I just don't know how can I add rows of Table#1 and Table#2 where "Qty" is bigger than "0" into Table Final.

table structure

Note: id column of each tables is PRIMARY KEY AUTOINCREMENT

CL.
  • 173,858
  • 17
  • 217
  • 259
Farshad Kazemi
  • 358
  • 1
  • 4
  • 16
  • What is the error you are getting after implementing @CL's answer? – ngrashia Sep 22 '14 at 09:03
  • @NishanthiGrashia, when I call **insertFinalTable()** the application would be crashed !!! – Farshad Kazemi Sep 22 '14 at 09:27
  • Do not change the question to something else; this would invalidate the answers. If you have another problem, ask a new question. (Also see [Unfortunately MyApp has stopped. How can I solve this?](http://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this).) – CL. Sep 22 '14 at 09:35
  • @CL., Tanks for your hint ;) I've edited my question because of : 1. my problem didn't solve and I added more explains ... 2. I didn't see **Answer Your Question** button to add more explains ... – Farshad Kazemi Sep 22 '14 at 09:41
  • @CL., What should I do?! Add extra explains by **add answer to my question** or **ask new question** ?! – Farshad Kazemi Sep 22 '14 at 10:28
  • An answer is not a question. To ask a question, use the "Ask Question" button. – CL. Sep 22 '14 at 12:28

2 Answers2

2
INSERT INTO "Table Final"(Product, Qty)
SELECT Product, Qty FROM "Table #1" WHERE Qty > 0
UNION ALL
SELECT Product, Qty FROM "Table #2" WHERE Qty > 0;
CL.
  • 173,858
  • 17
  • 217
  • 259
  • Dear CL, Tanks a lot for your answer. I've not known **UNION ALL** at all !!! [Unfortunately, I can't Vote your answer because of I'm new member of **StackOverFlow** ] – Farshad Kazemi Sep 20 '14 at 11:12
0

You could use unionwordkey to achieve this.

INSERT INTO Final(Product, Qty)
(SELECT Product, Qty FROM t1 where Qty > 0)
UNION ALL
(SELECT Product, Qty FROM t2 where Qty > 0)

Hope it helps

zozelfelfo
  • 3,776
  • 2
  • 21
  • 35