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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:00:30+00:00 2026-05-16T21:00:30+00:00

Greetings, I’ve got a query that I’m struggling with, this is the first time

  • 0

Greetings, I’ve got a query that I’m struggling with, this is the first time that I am encountering this type of query.
I have two table as shown below.

xid is the primary key in parent_tbl1, while xid is the foreign key in child_tbl2

parent_tbl1

xid pub 
1    1    
2    1    
3    0    
4    1

child_tbl2

id ttype fno xid  qnty
1  A       0    1    0
2  A       1    1    3
3  B       1    1    4
4  A       1    2    1  
5  A       1    3    2
6  A       1    4    3
7  A       1    4    1
8  A       1    1    1

Below is the exlanation of the query in parts, which will then need to make up the whole query.

I need the SUM of qnty in child_tbl2:

1) Who’s parent’s pub is ‘1’
Therefore, id 5 is eliminated from child_tbl2, this is because xid 3 is 0 in parent_tbl1

Results:
child_tbl2

id ttype fno xid qnty
1  A       0    1    0
2  A       1    1    3
3  B       1    1    4
4  A       1    2    1
6  A       1    4    3
7  A       1    4    1
8  A       1    1    1

2) AND who’s parent table has ttype ‘A’ in the child table
Therefore, id 3 is eliminated from the existing results because id 3’s ttype is B

Results:
child_tbl2

id ttype fno xid qnty
1  A       0    1    0
2  A       1    1    3
4  A       1    2    1
6  A       1    4    3
7  A       1    4    1
8  A       1    1    1

3) AND who’s parent has ‘0’ as one it’s fno’s in the child_tbl2
Therefore, id 4, 6 & 7 are eliminated from the existing results, this is because 0 was not found in one of their fno’s, while 0 was found as one of xid 1’s fno

Results:
child_tbl2

id ttype fno xid qnty
1  A       0    1    0
2  A       1    1    3
8  A       1    1    1

The answer for the query should be 4

Below is what i’ve got.

SELECT sum(child_tbl2.qnty), parent_tbl1.xid, parent_tbl1.pub, child_tbl2.ttype, child_tbl2.fno, child_tbl2.xid 
FROM parent_tbl1, child_tbl2
WHERE parent_tbl1.xid = child_tbl2.xid
AND parent_tbl1.pub = '1'
AND child_tbl2.ttype = 'A'

AND child_tbl2.fno ? 

If it is possible, I do not know how to tell the dbms (MySQL) to check if Zero is one of the fno’s.
If I say “AND child_tbl2.fno = ‘0’”, I will be saying that the result’s fno should be 0. I do not want that, I need zero to be one of the fno’s in order for the query to SUM all the qnty in that particular xid

  • 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-05-16T21:00:30+00:00Added an answer on May 16, 2026 at 9:00 pm
    SELECT SUM(DISTINCT src.qnty) as qnty
    FROM tbl2 AS src
    INNER JOIN tbl1 AS pub
      ON src.xid=pub.xid
    INNER JOIN tbl2 AS fno
      ON pub.xid=fno.xid
    WHERE pub.pub=1
      AND src.ttype='A'
      AND fno.fno=0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Greetings! I have an issue here that i can't find. I am getting a
Greetings, I have a large piece of software developed in Eiffel. It is possible
Greetings! I've got a Google App Engine Setup where memcached keys are prefixed with
Greetings, I'm uploading an image to my server using the following code: http://cocoadev.com/index.pl?HTTPFileUploadSample However,
Greetings, I've encountered a seemingly bizarre issue, and was wondering if anyone is able
Greetings, I am trying to run an SQL Script uploaded using Application Express (APEX),
Greetings, I am the program writer for the rebellion against the evil galactic empire.
Greetings Overflowers, To my understanding (and I hope I'm not right) changes to indices
Greetings, I am having a lot of issues during implementation of a model driven
Greetings, I'm trying to implement a tableview with asynchronously loading images (80px x 60px).

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.