Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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.


In reply to Re: Basic Perl trumps DBI? Or my poor DB design? by dragonchild
in thread Basic Perl trumps DBI? Or my poor DB design? by punch_card_don

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2024-04-26 04:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found