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 7971621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:40:46+00:00 2026-06-04T07:40:46+00:00

I got 2 tables, table1 & table2. table1 have fields: id atype adesc aid

  • 0

I got 2 tables, table1 & table2.

table1 have fields:

id
atype
adesc
aid

table2 have fields:

id
aid
adesc
value_1
value_2

$query1 = mysql_query("Select DISTINCT atype from table1");
while($row = mysql_fetch_array($query1)){
    $atype = $row['atype'];
    $query2 = mysql_query("Select adesc from table1 where atype='$atype' and aid IN (Select aid from table2 ) order by id asc");
    while($row2 = mysql_fetch_array($query2)){
        // i know query2 can only get adesc, so i need value_1 and value_2 in this
        echo $row2['adesc'] .'>> '. (this should be value1 from table2) .'>> '. (this should be value2 from table2);
    }
}

I want to get the value_1 and value_2 too. Any help would be appreciated.

EDIT:
table1 values are in my database (atype, aid, adesc respectively):

type1 111 'this is type 1'
type1 111 'this is type 1'
type2 112 'this is type 2'
type3 113 'this is type 3'
type4 114 'this is type 4'
type1 111 'this is type 1'
type4 114 'this is type 4'
type2 112 'this is type 2'

values on my table2 (aid,adesc,val1,val2, respectively):

111  'this is type 1' 100 50
111  'this is type 1' 100 50
112  'this is type 2' 300 500
113  'this is type 3' 100 50
112  'this is type 2' 100 50
114  'this is type 4' 100 50
111  'this is type 1' 100 50

what i really want to project is this:

type1
      (sum)value_1 (sum)value_2
type2 
      (sum)value_1 (sum)value_2
type3
      (sum)value_1 (sum)value_2
type4
      (sum)value_1 (sum)value_2
  • 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-04T07:40:47+00:00Added an answer on June 4, 2026 at 7:40 am
        $query2 = mysql_query("Select t1.adesc, t2.value_1, t2.value_2 from table1 as t1, table2 as t2 where t1.atype='$atype' and t1.aid = t2.aid order by t1.id asc");
    
        while($row2 = mysql_fetch_array($query2)){
            // i know query2 can only get adesc, so i need value_1 and value_2 in this
            echo $row2['adesc'] .'>> '. $row2['value_1'] .'>> '. $row2['value_2'];
        }
    

    upd:

    $sql = <<<SQL
    select t1.adesc, sum(t2.value_1) as v1, sum(t2.value_2)  as v2
    from 
    table1 as t1,
    table2 as t2
    
    where 
    t1.aid = t2.aid 
    group by t1.atype
    
    order by t1.atype asc
    SQL;
    $query = mysql_query($sql);
    while($row = mysql_fetch_array($query2)){
        // i know query2 can only get adesc, so i need value_1 and value_2 in this
            echo $row['adesc'] .'>> '. $row['v1']  .'>> '. $row['v2'];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got two tables: Event +----------+---------+--------------+ | event_id | name | date |
I've got two tables: Topics -name and Queries -topic_id A query can have a
I want to join 4 tables which have group by , order by &
I have a PHP script and MSSQL tables, I got the answer key in
I've got a gridview that populates from four tables, and the select command (shown
HI, I have Ling Table with MyObject. It has got fields: Id Number Name
I have 3 tables, Role[roleId, roleName] , Token[tokenID, tokenName] & ROLETOKENASSOCIATION[roleId, tokenID] . The
while working on osCommerce-3 i got the table structure for category & categories_description as
I got two tables Product(Productname VARCHAR(10), Rating REAL) and Review(RatingID INT, Productname VARCHAR(10), Rating
I got two tables in my database: user and call. User exists of 3

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.