471,870 Members | 1,505 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,870 software developers and data experts.

Help! MySQL LEFT JOIN probelm in Perl

Hi All

I have a sticky problem! Its a LEFT JOIN sql statement which works fine in MySQL but not when called in Perl. Any ideas?

I have 2 tables: campaigns & companies. I'm trying to join them so that all columns of both tables are returned when 2 fields match across the tables and some additional tests in the first table. It works fine in MySQL but returns an empty set when called in Perl. Is there some limitation in Perl or a better way to format the command for it to work from Perl?

Here is the SQL statement which works fine when tried directly inside MySQL:

Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM campaigns LEFT JOIN companies ON campaigns.DestinationURL=companies.Website WHERE (campaigns.BudgetAvailable>0 AND campaigns.SearchWebs LIKE "%google%") ORDER BY campaigns.MaxPayPerClick DESC LIMIT 6
And here is the Perl code:

Expand|Select|Wrap|Line Numbers
  1. my $query = qq{ SELECT * FROM campaigns LEFT JOIN companies ON campaigns.DestinationURL=companies.Website WHERE (campaigns.BudgetAvailable>0 AND campaigns.SearchWebs LIKE "%$website%") ORDER BY campaigns.MaxPayPerClick DESC LIMIT 6 };
where $website has the variable passed into it.

Please help me if you can!!!

Thanks.
Feb 18 '09 #1
3 2863
KevinADC
4,059 Expert 2GB
just guessing, try escaping the % symbols in the perl code in the query:

\%$website\%
Feb 18 '09 #2
Icecrack
174 Expert 100+
try:
Expand|Select|Wrap|Line Numbers
  1. my $query =("SELECT * FROM campaigns LEFT JOIN companies ON campaigns.DestinationURL=companies.Website WHERE campaigns.BudgetAvailable>0 AND campaigns.SearchWebs LIKE '%$website%' ORDER BY campaigns.MaxPayPerClick DESC LIMIT 6 ");
  2.  
Feb 19 '09 #3
Hi,

What is the error your getting

with Regards
sivashanmugam
Feb 26 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

9 posts views Thread by Tom | last post: by
4 posts views Thread by Sarir Khamsi | last post: by
6 posts views Thread by wukexin | last post: by
3 posts views Thread by Colin J. Williams | last post: by
7 posts views Thread by Corepaul | last post: by
5 posts views Thread by Steve | last post: by
NeoPa
reply views Thread by NeoPa | last post: by
aboka
reply views Thread by aboka | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.