CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
subquery not executing

 



sanyukta
Novice

Mar 2, 2004, 10:03 PM

Post #1 of 3 (292 views)
subquery not executing Can't Post

How to make a subquery work?

$stmt = "select 1 from partitiondata where part_id like(select part_id from Partition where part_name='$partition');
$sth=$dbh->prepare(stmt);
$sth->execute;

This is giving syntax error...can anyone tell why??

Thanks,
Sanyukta.

Partition

- part_id
- part_name

partitiondata
-part_id
-totalspace
-area


davorg
Thaumaturge / Moderator

Mar 2, 2004, 11:21 PM

Post #2 of 3 (291 views)
Re: [sanyukta] subquery not executing [In reply to] Can't Post

This is an SQL problem. Not a Perl problem. Please ask your questions in the appropriate place.

I think that your query would be better written as:

Code
select 1 from partitiondata where part_id in 
(select part_id from Partition where part_name='$partition')

But it's also possible that you are using a database that doesn't support sub-selects. In that case you could rewrite it as:

Code
select 1 
from partitiondata d, partition p
where p.part_id = d.part_id
and p.part_name = '$partition'

This changes the sub-select into a join.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


sanyukta
Novice

Mar 3, 2004, 12:30 AM

Post #3 of 3 (288 views)
Re: [davorg] subquery not executing [In reply to] Can't Post

Thanks Dave !!! I think the problem was with 'like'. Thanks again. I need to improve on lot of things:)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives