Computer Association of SIUE - Forums

CAOS Forums => Questions and Answers => Topic started by: Bryan on 2006-02-07T10:16:14-06:00 (Tuesday)

Title: need some help avoiding running a large amount of queries.
Post by: Bryan on 2006-02-07T10:16:14-06:00 (Tuesday)
Okay I have 7 different variables.  Each of those variables have different set information that they can be.

ex.  Time - lunch/afternoon/other , Day of Week - M/T/W/R/F, etc.

I'm trying to come up with a way to query a database that's holding all of this informatoin and figure out what combination results in the best setup for certain people.  Running on straight combinations results in running 240 queries.  Which I want to avoid, if possible.  Several people suggested this is a class AI problem.  only problem is that I never took AI and can't seem to find any references to it.

Anyone have any ideas?  Worst case scenario I'm going to run it as a stored procedure.  All of the data is being held in my webserver in a MySQL database.
Title: Re: need some help avoiding running a large amount of queries.
Post by: EvilAndrew on 2006-02-07T11:49:42-06:00 (Tuesday)
Have you tried the SELECT command (http://dev.mysql.com/doc/refman/5.0/en/select.html) with an IN parameter (http://www.1keydata.com/sql/sqlin.html)?

For example:
SELECT * FROM tblPeople WHERE FavoriteDay IN ('FRI', 'SAT', 'SUN')

I think you can also put another SELECT Statement in the "IN" part but I am not sure:
SELECT * FROM tblPeople WHERE FavoriteDay IN (SELECT Days FROM tblWeekends)
Title: Re: need some help avoiding running a large amount of queries.
Post by: Geoff Schreiber on 2006-02-07T18:17:34-06:00 (Tuesday)
What Andrew said is possible, but if the tables holding the information are related in any way, the query speed is quicker by using an inner or outer join than in using a subquery.

SELECT [tablename.]fieldname [,[tablename.]fieldname ...] FROM tablename INNER JOIN tablename2 ON tablename.fieldname = tablename2.fieldname2