• Welcome to Computer Association of SIUE - Forums.

need some help avoiding running a large amount of queries.

Started by Bryan, 2006-02-07T10:16:14-06:00 (Tuesday)

Previous topic - Next topic


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.
Bryan Grubaugh
Quickly aging alumni with too much time on his hands
Business Systems Analyst, Scripps Networks.


Have you tried the SELECT command with an IN parameter?

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)

Geoff Schreiber

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

Geoff Schreiber
Project Engineer
FASTechnology Group