troubleshooting Question

MySQL Subquery Help

Avatar of t3chguy
t3chguyFlag for United States of America asked on
MySQL Server
2 Comments1 Solution394 ViewsLast Modified:
I'm trying to run a query with multiple subqueries to extract data from each row in the table.  

The problem that I'm having is that the query errors out and returns "operand should contain 1 column(s).

I've attached both the query as well as the structure of the database and some sample data.

Thank you!

----------------

$sql = "SELECT Q.hirerev, Q.hirebudget, Q.date,
            (SELECT Q.hirerev, Q.hirebudget FROM revenue_graph WHERE date = '2011-05-01') as May,
            (SELECT Q.hirerev, Q.hirebudget FROM revenue_graph WHERE date = '2011-06-01') as June,
            (SELECT Q.hirerev, Q.hirebudget FROM revenue_graph WHERE date = '2011-07-01') as July,
            (SELECT Q.hirerev, Q.hirebudget FROM revenue_graph WHERE date = '2011-08-01') as August,
            (SELECT Q.hirerev, Q.hirebudget FROM revenue_graph WHERE date = '2011-09-01') as September,
            (SELECT Q.hirerev, Q.hirebudget FROM revenue_graph WHERE date = '2011-10-01') as October,
            (SELECT Q.hirerev, Q.hirebudget FROM revenue_graph WHERE date = '2011-11-01') as November,
            (SELECT Q.hirerev, Q.hirebudget FROM revenue_graph WHERE date = '2011-12-01') as December,
            (SELECT Q.hirerev, Q.hirebudget FROM revenue_graph WHERE date = '2012-01-01') as January,
            (SELECT Q.hirerev, Q.hirebudget FROM revenue_graph WHERE date = '2012-02-01') as February,
            (SELECT Q.hirerev, Q.hirebudget FROM revenue_graph WHERE date = '2012-03-01') as March,
            (SELECT Q.hirerev, Q.hirebudget FROM revenue_graph WHERE date = '2012-04-01') as April
            FROM revenue_graph Q
            WHERE Q.date >='2011-05-01' AND Q.date <='2012-04-01'
            ORDER BY Q.date DESC";
dataexample.png
structure.png
ASKER CERTIFIED SOLUTION
Michael Carrillo
Information Systems Manager
Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros