SQL optimization
Posted: Sun Nov 06, 2005 11:14 am
I'm by no means an expert in SQL, but...
I once read that in order optimize queries you should keep them as brief as possible (Select only specific fields, reduce the amount of table joins, etc...)
Now my question is...
Assuming I have three tables (table1, table2, table3) and currently have a simple SQL JOIN statement to pull data from each table returning a single resultset...
Not sure if the above is syntactically correct but i'm sure you'll get the idea...
Anyways...please correct me if I'm wrong, but would the above be faster if I pulled the individual record from each table using three seperate queries:
And then merged the results using PHP??? Not sure how I would go abouts doing that, but i'm sure it's possible - so long as multi-result queries yield the same number of results...???
Anyways the important question here is...is three seperate queries faster than a single query using implicit JOIN's...???
I'm not looking for practical here...i'm looking for reality...i'm not going to use theo above technique...I just need to know
Cheers
I once read that in order optimize queries you should keep them as brief as possible (Select only specific fields, reduce the amount of table joins, etc...)
Now my question is...
Assuming I have three tables (table1, table2, table3) and currently have a simple SQL JOIN statement to pull data from each table returning a single resultset...
Code: Select all
SELECT * FROM table1, table2, table3 WHERE table1.pkid = table2.pkid AND table2.pkid = table3.pkid AND table1.pkid = 12Anyways...please correct me if I'm wrong, but would the above be faster if I pulled the individual record from each table using three seperate queries:
Code: Select all
SELECT * FROM table1 WHERE pkid = 1
SELECT * FROM table2 WHERE pkid = 1
SELECT * FROM table3 WHERE pkid = 1Anyways the important question here is...is three seperate queries faster than a single query using implicit JOIN's...???
I'm not looking for practical here...i'm looking for reality...i'm not going to use theo above technique...I just need to know
Cheers