• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: SQL SUM up specific rows without subquery returning more than one row

Resolved: SQL SUM up specific rows without subquery returning more than one row

0
By Isaac Tonny on 16/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

There are a few posts that seem similar to this problem, but I cannot find the solution to this problem through those posts.
I have the following two tables that I am working with (I’m not posting the full table, just as much is needed to understand the problem):
Table 1: employee
emp_id first_name last_name
102 Michael Scott
108 Jim Halpert

Table 2: works_with
emp_id client_id total_sales
102 401 267,000
102 406 15,000
108 402 22,500
108 403 12,000

If this table data is not sufficient, I can go back and add more.
The issue I am having is with this code:
When I run the code like this, I get the error: “SQL Error (1242): Subquery returns more than 1 row.”
I saw a solution online that said to add “Any” before the subquery, but this is the resulting table:
ID First Name Last Name Sales
102 Michael Scott 0

This is what I want the resulting table to look like:
ID First Name Last Name Sales
102 Michael Scott 282,000
108 Jim Halper 34,500

I am confused as to how I would fix this. Any help is greatly appreciated!

Answer:

This should give you the results you need where table 1 is the first table you mentioned and table 2 is the second

If you have better answer, please add a comment about this, thank you!

heidisql sql
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: navigate and redirect not redirecting to path in react router

24/03/2023

Resolved: Time Complexity: Find the number of people who know a secret leetcode 2327

24/03/2023

Resolved: Best way to create 3d matrix of variables in PULP

24/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.