Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8013235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:35:08+00:00 2026-06-04T19:35:08+00:00

I want to execute two select queries in one go, but the data isn’t

  • 0

I want to execute two select queries in one go, but the data isn’t related to each other so a LEFT JOIn etc. will not do.. because then I end up with data I can’t use.

What I got so far is;

$sql .= "SELECT *,
        servertypes.id as servertypeID, 
        servertypes.name as servertypeName 
       FROM servertypes";

$sql .= " JOIN".
    " (SELECT *,
        periods.id as periodID,
        periods.daysForSorting as periodNumber,
        periods.text as periodsText
       FROM periods
       ) AS periods";

$res = mysql_query($sql);
if(!$res) die("database_error_cant_select_data : ".$sql." : ".mysql_error());

But now how do I access servertypes and periods separately? I think I have to stop using JOIN altogether but I wouldn’t know…

To illustrate what I mean, it’s something like:

while ($row = mysql_fetch_assoc($res["servertypes"]))
{
    print_r($row);
    echo"<br/><br/>";
}

while ($row = mysql_fetch_assoc($res["periods"]))
{
    print_r($row);
    echo"<br/><br/>";
}

Is this possible using only one query?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T19:35:10+00:00Added an answer on June 4, 2026 at 7:35 pm

    Normally, you could do something like that IF both query return the same column number

    Table1
    -----------
    ProductID
    Price
    Qty
    
    Table2
    -----------
    ProductID
    Price
    Qty
    
    $Query = '(SELECT "Table1" AS Source, * FROM Table1) UNION (SELECT "Table2" AS Source, * FROM Table2)';
    
    $Data = array('T1' => array(), 'T2' => array());
    while($Assoc = mysql_fetch_assoc($Query)){
        switch(strtoupper($Assoc['Source'])){
            case 'TABLE1':
                $Data['T1'][] = $Assoc;
                break;
    
            case 'TABLE2':
                $Data['T2'][] = $Assoc;
                break;
    
            default:
                break;
        }
    }
    
    //  $Data['T1'] now hold everything from Table1
    //  $Data['T2'] now hold everything from Table2
    

    But here, nothing is related. So to answer your question : no you cannot do what you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to execute one of the two queries here based on a parameter.
Hi I want to execute this two queries and display the results at the
I want to build a shell script to execute the following two commands, but
I want to index two different OntModel and execute sparql queries on them. For
I want to execute a simple join on two tables after connecting two columns
I want to execute FetchXML queries in a CRM 2011 environment using the CRM
I have two databases, one is located in localhost, the other one in located
Currently I'm running these two queries: SELECT COUNT(*) FROM `mytable` SELECT * FROM `mytable`
I have a small workspace with 3 projects. One main (Swing) application, two other
I want to do a top5 of two tables that are not related with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.