Page 1 of 1

How to create One Master Query

Posted: Mon Sep 26, 2011 8:50 am
by wizzuriz
Hello All,

This is not going to be easy and I tried working on this for some time now, what I want is to create a master query where I select data from 4 different tables use the 4 values in a calculation and insert it into a other table.

If you have any clue on how to create such a query please let me know..

And if this make no sense please let me know that to..

Best regards
Wizzuriz

Re: How to create One Master Query

Posted: Mon Sep 26, 2011 4:57 pm
by jacek
What is the calculation ? Also, what are the tables like, are they linked in some way ?

Re: How to create One Master Query

Posted: Mon Sep 26, 2011 5:07 pm
by wizzuriz
1. The calculation is $variable = $row['value1'] * pow(1 - $row['value2'], $step1) * $row["value3"] * $row['value4'] * $row["value5"];

2. The tables, I have 5 different tables holding 160 rows with 15 columns = 2400 different values in each table. I need to select a specific value from each table and use them in the calculation..

3. they are not linked in any way, I don't know but there might be a way to do that if that will help I cloud take a look at it..

Best regards

Wizzuriz

Re: How to create One Master Query

Posted: Tue Sep 27, 2011 3:16 pm
by jacek
Well, you probably need to do it with 6 queries if there is no link at all. 5 for selecting from each table and one for inserting into the new one.

I would not like to do any single function that involved more than two really, so maybe a re-think is needed on your database structure.

Re: How to create One Master Query

Posted: Tue Sep 27, 2011 4:25 pm
by wizzuriz
Hi Jacek,

Yea its was a big problem, there was way to much code in that function in the end.

I did 4 function with 2 query in each and then got them in the calculating function, its works fine.

Now I need to learn how to select 90 rows in a table and put them all in a array and move that array to a other function any idea?

Any way thanks for the help with the master query its working fine now with 4 small helping it :)

Best regards
Wizzuriz.

Re: How to create One Master Query

Posted: Wed Sep 28, 2011 3:14 pm
by jacek
Well you can limit the number of rows you select using LIMIT
SELECT `id` FROM `table` LIMIT 0, 90
would take the first 90.

You put them into an array as normal, and you could then have the function return that array ?