Anything can be done in Perl :-). The issue here is the SQL.
X IN (val1, val2, ...) only returns true(1) or false(0) so your where clause is merely checking to see if regnum and month exist in the pick list (see IN()). It doesn't compare the position in the list at all. To compare position, you (a) need an SQL function to retrieve the position within a list (b) need to compare the two positions one to another.
Retrieving the order number of an item in a list isn't a standard SQL built-in function so you will have to write your own SQL function. Lets call it LIST_POSITION(...). Then your generated query would look something like this:
# Note: reordered where clause # to put quick to evaluate conditions first # the query has a better chance of actually being optimized my $statement = <<EOF; SELECT name, last_name, reg_num, month, year FROM members WHERE year='2009' AND LIST_POSITION(month, $month_values) = LIST_POSITION(reg_num, $reg_num_values) EOF
In MySQL, you can define the custom function using the CREATE FUNCTION. You can also write Perl stored procedures.
Your mileage may vary with other SQL dialects.
Best, beth
In reply to Re: Query using more than one array!
by ELISHEVA
in thread Query using more than one array!
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |