passing array as subquery to a SQL query
From: Kamran (mkazeem_at_isb.paknet.com.pk)
Date: 09/27/04
- Next message: Ron Reidy: "RE: passing array as subquery to a SQL query"
- Previous message: Tommy: "DBD::ADO not returning error message"
- Next in thread: Ron Reidy: "RE: passing array as subquery to a SQL query"
- Maybe reply: Ron Reidy: "RE: passing array as subquery to a SQL query"
- Reply: Jeff Zucker: "Re: passing array as subquery to a SQL query"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
To: dbi-users@perl.org Date: Tue, 28 Sep 2004 00:20:28 +0600
Hello all,
I am new to the list.
I am trying to achieve a goal in PERL. That is:
I have a table say students with fields (id int, name char(10) ) .
I have data like:-
ID NAME
== ==========
1 Kamran
2 Imran
3 Amir
4 Abid
I have an array in perl as :-
my @ids = (1,2,3) ;
I want to select those records from the table students , which do not
have ID in the array @ids. (This should give me 4 and 'Abid' ) .
I am trying to do it as the follwoing code:-
########################## code snip start #########################
my @ids = (1,2,3) ;
my $SQL = "select * from students where id in (@ids)";
# I am using the syntax of subquery in the above line .
my $sth = $slavedbh->prepare($SQL) || die "Cannot prepare SQL
statement\n";
my $howmany = $sth->execute || die "Cannot select from table\n";
######################### code snip end ############################
I am using Postgresql 7.3 on Redhat Linux 9. I have perl 5. Rather
everything is what comes bundled with Redhat 9. nothing extra.
I don't know if this problem has been addressed in past. If so please
point me in the right direction.
Thanks in advance for your time and help.
Kamran
- Next message: Ron Reidy: "RE: passing array as subquery to a SQL query"
- Previous message: Tommy: "DBD::ADO not returning error message"
- Next in thread: Ron Reidy: "RE: passing array as subquery to a SQL query"
- Maybe reply: Ron Reidy: "RE: passing array as subquery to a SQL query"
- Reply: Jeff Zucker: "Re: passing array as subquery to a SQL query"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]