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

  • Home
  • SEARCH
  • 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 8186799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:20:51+00:00 2026-06-07T02:20:51+00:00

Hi i have to write a mysql query i will explain the query how

  • 0

Hi i have to write a mysql query i will explain the query how i want to work.

I have two table

A

CREATE TABLE IF NOT EXISTS `A` (
  `field1` int(10) NOT NULL AUTO_INCREMENT,
  `field2` int(10) NOT NULL,
  `field3` int(10) NOT NULL,
  `field4` varchar(255) DEFAULT NULL,
  `fields5` int(10) NOT NULL,
  `field6` varchar(255) NOT NULL,
  `field7` varchar(255) NOT NULL,
  `field8` int(10) NOT NULL,
  `field9` tinyint(1) NOT NULL COMMENT '1=for enabled resource 0= for
disabled resource',
  PRIMARY KEY (`field1`);

table B

CREATE TABLE IF NOT EXISTS `estimate_resource_mth` (
  `field1` int(10) NOT NULL AUTO_INCREMENT,
  `field2` int(10) NOT NULL,
  `field3` int(10) NOT NULL,
  `field4` int(10) NOT NULL,
  PRIMARY KEY (`field1`) ;

There is one to many reference from tableA to tableB that is A.field1 multiple reference to B.table2. Now i will explain what i need to get, i have an id which fetch the data from table A using where condition i need to return this list with the sum of filed4 in tableB(field2 in tableB reference to tableA and it may be a multple row one to many relatio ). How could i got a this data in a single 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-07T02:20:53+00:00Added an answer on June 7, 2026 at 2:20 am

    Your description is poor and your generic column names are not very helpful, but if I understand, tableB.field2 references tableA.field1. In that case, a LEFT JOIN with an aggregate SUM() on tableB.field4 will do the job.

    SELECT
      tableA.field1,
      SUM(tableB.field4) AS the_sum
    FROM
      tableA 
      LEFT JOIN tableB ON tableA.field1 = tableB.field2
    WHERE
      /* IN() for multiple possible vals. Use = if only 1 val needed
         and then the GROUP BY is unnecessary */
      tableA.field1 IN ('val1','val2',val3')
    GROUP BY tableA.field1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi i'm struggling to write a particular MySQL Join Query. I have a table
I have the following mysql query. Could you please tell me how to write
Hi I have a query which is very straightforward to write in mysql but
I have a slow MySQL query in my application that I need to re-write.
Ok. I have my query written finally for my php file (which will write
I am attempting to write a MySQL query that will return element whose details
I have write this code but it does work only if I am already
I have a table that looks something like this: CREATE TABLE student_results(id integer, name
I have two tables. Table Emp id name 1 Ajay 2 Amol 3 Sanjay
I am trying to write a stored procedure in MySQL which will perform a

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.