This isn't a Perl question so far as it's a relational database design question. So, I'll treat it as such.
You have two different tables:
- respondent, where you have info about the respondent - name, address, etc
- responses, where you list the responses each respondent took
So, given the info you have, I would design tables as such:
CREATE TABLE respondent (
id unsigned int not null auto_increment primary key
,name varchar(20)
# , etc ...
);
CREATE TABLE response (
id unsigned int not null auto_increment primary key
,name varchar(20)
);
CREATE TABLE responses (
respondent unsigned int
,response unsigned int
,PRIMARY KEY (respondent, response)
);
Then, I would create the query as such:
SELECT A.respondent AS respondent
FROM responses A JOIN responses B on (A.respondent = B.respondent)
WHERE A.response = ?
AND B.response = ?
I would call it as such:
my $sth = $dbh->prepare_cached( $sql );
$sth->execute( $response_x, $response_y );
$sth->bind_columns( \my ($respondent) );
my @respondents;
while ($sth->fetch)
{
push @respondents, $responses;
}
$sth->finish;
Depending on the power of your database server, this should run in under 3-5 seconds, given the numbers you mentioned. I should warn you that my experience is primarily with MySQL 4.1.x, so I don't have a lot of knowledge of the 3.x series.
I would also turn on query_caching, which will help a bunch with the reporting. I personally have found a 90% improvement with certain kinds of reporting when I turned it on.
Being right, does not endow the right to be rude; politeness costs nothing.
Being unknowing, is not the same as being stupid.
Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.