Does this query fetch unnecessary information? Should I change the query?
Posted
by Camran
on Stack Overflow
See other posts from Stack Overflow
or by Camran
Published on 2010-05-07T13:47:12Z
Indexed on
2010/05/07
13:48 UTC
Read the original article
Hit count: 201
I have this classifieds website, and I have about 7 tables in MySql where all data is stored. I have one main table, called "classifieds".
In the classifieds table, there is a column called classified_id. This is not the PK, or a key whatsoever. It is just a number which is used for me to JOIN table records together.
Ex:
classifieds table: fordon table:
id => 33 id => 12
classified_id => 10 classified_id => 10
ad_id => 'bmw_m3_92923'
This above is linked together by the classified_id column.
Now to the Q, I use this method to fetch all records WHERE the column ad_id matches any of the values inside an array, called in this case $ad_arr:
SELECT mt.*, fordon.*, boende.*, elektronik.*, business.*, hem_inredning.*, hobby.*
FROM classified mt
LEFT JOIN fordon ON fordon.classified_id = mt.classified_id
LEFT JOIN boende ON boende.classified_id = mt.classified_id
LEFT JOIN elektronik ON elektronik.classified_id = mt.classified_id
LEFT JOIN business ON business.classified_id = mt.classified_id
LEFT JOIN hem_inredning ON hem_inredning.classified_id = mt.classified_id
LEFT JOIN hobby ON hobby.classified_id = mt.classified_id
WHERE mt.ad_id IN ('$ad_arr')";
Is this good or would this actually fetch unnecessary information?
Check out this Q I posted couple of days ago. In the comments HLGEM is commenting that it is wrong etc etc. What do you think?
http://stackoverflow.com/questions/2782275/another-rookie-question-how-to-implement-count-here
Thanks
© Stack Overflow or respective owner