I currently have 5 tables:
trialSum
-------------
id total
-------------
1 2000
2 1000
3 500
trialLand
-------------
id total
-------------
1 1000
2 250
3 500
trialImp
-------------
id total
-------------
2 250
trialBldg
-------------
id total
-------------
1 1000
2 500
trial
---------------------
id name info
---------------------
1 xxxxx xxxxx
2 xxxxx xxxxx
3 xxxxx xxxxx
4 xxxxx xxxxx
The trial table will have the most entries into and all of the “id” fields match up with each other. Each table will have over 7000 entries in them. I am trying to create one big table that looks like:
trial
----------------------------------------------------------------------
id name info totalSum totalLand totalImp totalBldg
----------------------------------------------------------------------
1 xxxxx xxxxx 2000 1000 0 1000
2 xxxxx xxxxx 1000 250 250 500
3 xxxxx xxxxx 500 500 0 0
4 xxxxx xxxxx 0 0 0 0
If I do a giant MySQL query that has 4 left joins, it take over 40 minutes to complete. There has to be an easier way. Thanks!
I would say that, the left join is indeed a good way to do this. Do you have indexes on those id columns? Try adding indexes and the speed should improve. Remember to use EXPLAIN to confirm the indexes are being used appropriately. More on EXPLAIN http://www.dbtuna.com/article.asp?id=14 .