Help! MySQL LEFT JOIN probelm in Perl

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Scotsman
    New Member
    • Feb 2009
    • 2

    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:

    Code:
    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:

    Code:
    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.
    Last edited by eWish; Feb 26 '09, 01:46 PM. Reason: Please use the code tags
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    just guessing, try escaping the % symbols in the perl code in the query:

    \%$website\%

    Comment

    • Icecrack
      Recognized Expert New Member
      • Sep 2008
      • 174

      #3
      try:
      Code:
      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 ");

      Comment

      • sivashanmugam
        New Member
        • Feb 2009
        • 5

        #4
        Hi,

        What is the error your getting

        with Regards
        sivashanmugam

        Comment

        Working...