Connecting Tech Pros Worldwide Forums | Help | Site Map

Join two different queries?????

Alireza355's Avatar
Member
 
Join Date: Feb 2009
Location: Iran
Posts: 68
#1: Apr 22 '09
Dear all

I have one query which selects some items from my main table and inserts the results into a fresh temporary table. in this table, there is a column that remains empty to be filled with the results of a second query:

I also have another UPDATE query that updates the empty column with the result of adding columnA + columnB of the newly-filled table.

Sorry, I am not so good in English. Let me give an example:

In the new table, there are 3 columns: ColumnA , columnB and columnC
The table is fresh, and there is nothing in it.
The first query, selects some information and inserts them into the new table:

ColumnA=12500
ColumnB=6000
ColumnC=Null

Now the second query updates ColumnC to 6500

I had to do this because the first query sorts the records in a quite complicated manner and puts them into the new fresh table. Now the result of the calculation becomes meaningful. The sorting of the first query should be done FIRST and then the calculation should be done. of course if the calculation is done at the same time each row is inserted into the new table, nothing seems to be wrong theoretically to me.


Since there are thousands of records, is there a way I can join these two queries into a single query to save time?

Expert
 
Join Date: Jul 2008
Location: Maryland
Posts: 1,176
#2: Apr 22 '09

re: Join two different queries?????


It depends on what type of calculations you are doing beforehand, but in general you can do something like:
Expand|Select|Wrap|Line Numbers
  1. SELECT ColumnA, ColumnB, ColumnA + ColumnB as ColumnC FROM myTable...
Alireza355's Avatar
Member
 
Join Date: Feb 2009
Location: Iran
Posts: 68
#3: Apr 23 '09

re: Join two different queries?????


Dear ChipR,

Thank you so much for your reply.

It works perfect...
Reply