Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Combining query results

Posted on 2004-11-01
8
Medium Priority
?
228 Views
Last Modified: 2013-12-12
Hello,

I recently got assistance in the mysql forum on how to build a report that shows forum usage statistics over a period of 12 months.  So now I have 2 queries that give me the data, but to output the report properly I need this data to be in 1 result set.  So my question is if I have 2 queries, each returning 2 columns- how do I combine the results into a result set with 3 columns when 1 column is common between the 2 queries?

-------------------------
Month | Topics
==============
Aug    |  14
Sept   |   0
Oct     |  34

AND

-------------------------
Month | Posts
==============
Aug    |   5
Sept   |   17
Oct     |  20

INTO

-----------------------------
Month | Posts  |  Topics
================
Aug    |   5    |   14
Sept   |   17   |   0
Oct     |  20   |   34

Any ideas?
0
Comment
Question by:Mr_Shadow
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
8 Comments
 
LVL 2

Expert Comment

by:Silversoft
ID: 12470635
Hi

Is this what you looking for?

SELECT Topics, Posts FROM tbl_topic, tbl_post GROUP BY Month
0
 

Author Comment

by:Mr_Shadow
ID: 12479612
well not really, im not looking to alter my queries, lets say i have query 1 which produces columns A and B.  I have query 2 which produces columns A and C.  I need 1 query object that has A, B, and C.  The question is is there any way to manipulate queries in this way in PHP.  I know the obvious answer is 'make the database do it in one query', well assuming i absolutely cannot, is there any way php can help.
0
 
LVL 2

Expert Comment

by:Silversoft
ID: 12480672
Hmm... I think the only way to combine the query result of A,B and C is to alter your 2 queries and make it into 1 query like how i did it in the first post. If you would like to combine the two using PHP, I must say it's a mission, as you need to synchronize the rows so they match up. Another thing is that, you won't be able to do an ORDER BY if you have 2 queries forced into 1 query result, I suppose you can, but with extra extra coding and difficult to track errors.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 1

Accepted Solution

by:
InvolveIT earned 1000 total points
ID: 12565434

$res=mysql_query(query1)
for($k=0; $k < mysql_num_rows($res); $k++){
        @extract(mysql_fetch_array($res));
        $res2=mysql_query(SELECT TOPICS FROM query2 WHERE Month='$Month')
@extract(mysql_fetch_array($res));



0
 
LVL 1

Expert Comment

by:InvolveIT
ID: 12565455
I wasn't ready there
But I think the idea is clear, just query for your topics within the loop where you get your results from query1.
Then you have all the info together to list in a single line.
If that's what you are looking for.
0
 

Author Comment

by:Mr_Shadow
ID: 12896682
sorry for my unresponsiveness, i have since hired a programmer to get this information from 1 query- i have sent him InvolveIT's response as a possible way to do it, since he also says it is impossible with 1 query.  thanks
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question