How to create One Master Query

Post here if you need help with SQL.
Post Reply
wizzuriz
Posts: 53
Joined: Mon Jul 25, 2011 4:22 pm

How to create One Master Query

Post 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
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: How to create One Master Query

Post by jacek »

What is the calculation ? Also, what are the tables like, are they linked in some way ?
Image
wizzuriz
Posts: 53
Joined: Mon Jul 25, 2011 4:22 pm

Re: How to create One Master Query

Post 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
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: How to create One Master Query

Post 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.
Image
wizzuriz
Posts: 53
Joined: Mon Jul 25, 2011 4:22 pm

Re: How to create One Master Query

Post 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.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: How to create One Master Query

Post 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 ?
Image
Post Reply