SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Sep 2010
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Perplexing subquery problem

    I am using the MySQL Workbench 5.2.34 to write queries that will be used later on a php site. A particular query that returns a NULL value has me stumped (perhaps I have hit the limit of Red Bull and am missing something obvious):
    Code:
    SELECT sum(SalesAmount) 
    FROM HISTORY 
    WHERE PartNumber IN (SELECT PartNumber FROM MANIFEST_ITEMS WHERE manifestid = '905712');
    When I run the subquery independently, I get the expected results:
    Code:
    SELECT PartNumber 
    FROM MANIFEST_ITEMS 
    WHERE manifestid = '905712';
    When I run the outer query independently (with sample data that is returned by the subquery), I get the expected results:
    Code:
    SELECT sum(SalesAmount) 
    FROM HISTORY 
    WHERE PartNumber IN ('MC024LL/A','MC373LL/A','MC375LL/A','MC371LL/A');
    I think the issue is that in the third example, I have escaped my return values, but when the subquery is returning these values, they are not escaped. If that is the case, is it possible to automagically escape these subquery return values?


    Thank you!

  2. #2
    SitePoint Member
    Join Date
    Sep 2010
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Interestingly I found this:
    Querying MySQL database for strings containing forward slash | HOTORACLE

    So evidently the issue is with the results that have a forward slash in the PartNumber. Is there a way to double quote the return results from a subquery?

    Thank you.

  3. #3
    SitePoint Member
    Join Date
    Sep 2010
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I found the problem, my test data was bad!

    So, the query above does work as expected! A big Sorry! to those who have looked and wasted their time.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •