Page 1 of 1

Efficiency in MySQL queries - which is better?

Posted: Thu Mar 30, 2006 4:30 am
by real_mccoy
Hi Folks,
I have been using PHP/MySQL for a couple of years now, and am attempting to develop a "program guide", which lists radio or tv programs in a weekly schedule. The issue I am facing is this: I have decided to have each weekday as a field in the table, and if the program occurs on multiple days, those days will have the value "Y". When I go to display the program guide, I am wondering if I should:
A. pull all of the data out of the table and iterate through it multiple times, in order to display each day's programs consecutively - OR
B. conduct seven separate queries on the table, only pulling items which are marked for each day to display (i.e., "where Mon = 'Y'").

All told, there will only be about 100 items at most in the table, so it won't be a huge hit anyway. I'm just wondering what the most efficient way is to do it.

Opinons?

thanks in advance...

Posted: Thu Mar 30, 2006 5:05 am
by jrd
I would rather do the latter, A.

Er..... the latter would be B, the former would be A

Posted: Thu Mar 30, 2006 5:10 am
by real_mccoy
You mean you'd rather do the first one? I was thinking I'd rather do that, too, but am a little stumped as to how to iterate through and pick out each day's programs... once I've picked out all of Monday's programs, for instance, I then need to go through the results again and pick out Tuesday's, then ditto for Wednesday's, etc., etc. I just wonder if that's not more inefficient than seven small hits on the database...

What do you think?

Re: Efficiency in MySQL queries - which is better?

Posted: Thu Mar 30, 2006 6:36 am
by Roja
real_mccoy wrote: All told, there will only be about 100 items at most in the table, so it won't be a huge hit anyway. I'm just wondering what the most efficient way is to do it.
Depends on the table, the data, the mysql settings, the OS settings, and more.

Test in your environment, and find out.