Jump to content

Recommended Posts

Is there any way that i can combine the results.from multiple queries? I can't use left.join as im.reliant on results.. So is there any way?

 

Each set of query results have a time column for each row.. and basically after combining the results in a php array or something i want to order all the results cumulatively by time.. any way?

Link to comment
https://forums.phpfreaks.com/topic/253988-combine-results-of-several-queries/
Share on other sites

Okay thanks, I'll try my best to lay out the situation (syntax won't be correct as I'm doing this very quickly before work). My idea has come from the social network stream/feed etc where you get information about yourself and your friend aggregated.

 

However, in my case I'm using it for a project regarding companies.

 

So My first query is to select all the companies that are friends with the user (user_id):

 

SELECT friend_id FROM companies WHERE id = user_id

 

Then I want to get all the posts that the user makes and load these:

 

SELECT content, time FROM posts WHERE userid = user_id

 

Using the first equation, I want to get all the friend_id posts as well

 

 SELECT content, time FROM posts WHERE userid = friend_id

 

Also, in and amongst this, I'm going to try and get mutual friend posts as well but I need to think that one through even more.

 

From the two last queries you can see that there is a time value. Basically, I want the results combined and then ordered by their times from this.

 

Hope this helps a little.

and for what reason you can't do the 3 queries in just one sentence?...  there is a clear relationship among them.. you could get all the data that you need with 1 query and process/display it at you wish.

 

if that is not the route that you want to follow (??) then yes.. you can use UNION to mix data from queries 2 and 3

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.