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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:39:51+00:00 2026-06-14T00:39:51+00:00

I need help with the following SubQuery in MySQL SELECT … # Main query

  • 0

I need help with the following SubQuery in MySQL

 SELECT ... # Main query 
...      
... IN # Start of subquery that expects to return an array of a.id 
(SELECT a.id, a.multipler 
FROM a 
JOIN b ON a.id = b.id
GROUP BY(a.id)
HAVING COUNT(b.id) * a.multipler < 5)

What I want to achive is to group all a.id that exist in table b (b.id).
I want to count the results and mulitple with an unique mulitpler (a.multipler) for each a.id.

The problem here is that I want this to be a subquery: thus I cannot have 2 results. Though, in order to use “HAVING” I need to have each variable in the result set.

I only want/need “a.id” without “a.multipler” as the result. Any ideas to solve this?

Example code:

#table a
+------+-------------+
| a_id | a_multipler |  
+------+-------------+
|    1 | 2.000       |
|    2 | 0.560       |
|    3 | 1.000       |
|    4 | 1.200       |
|    5 | 2.000       | 
+----- +-------------+
#table b
+------+
| b_id | 
+------+
|    1 |
|    1 | 
|    1 |
|    4 | 
|    4 |
|    3 | 
+------+

# a.id 1: occurance in "table b": 3 x 2.000 ("a.id"==1 "a.multipler"). Fails, result >= 5

#a.id 2: Fails, no occurance of a.id in "table b".

#a.id 3: 1 x 1.000. Result < 5 OK

# and so on... "id" in "table a" (but not in "table b") is unique, 
# also a "id" in "table b" have to exist in "table a".

Wanted result given the above query (a.id): 4,3
NOT wanted result:

(a.id): 4,3

(a.multipler): 1.200, 1.000

  • 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-14T00:39:52+00:00Added an answer on June 14, 2026 at 12:39 am

    Then, wrap your subquery in another SELECTthat selects just the column you need:

    SELECT ... # Main query 
    ...      
    ... IN
    (SELECT pairs.id FROM               # <===          
        (SELECT a.id, a.multipler 
         FROM a 
         JOIN b ON a.id = b.id
         GROUP BY(a.id)
         HAVING COUNT(b.id) * a.multipler < 5) pairs)
    

    Any (sub)query results in a temporary table that can be further manipulated, in this case simply by selecting a subset of it columns.

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

Sidebar

Related Questions

I need help converting the following SQL query into LINQ: select s.teacherid,t.lastname,t.firstname,t.title,t.grade, count(s.TeacherID) from
I need help concerning following code: http://jsfiddle.net/8PsdE/ <SELECT ID=pizzasize NAME=pizzasize> <OPTION VALUE=s>small <OPTION VALUE=m>medium
I need help reproducing the following SQL statement to a statement that SQLite understands.
I need help with the following code that requires me to: Declare 3 double
Need help I have following code with classic asp <select name=state id=state> <option value=NJ>New
I need help with the following query. create table #table1 (id int not null
I need some help with the following: in a method create a new array
Need help in following code segment: static void Main(string[] args) { var customers =
I need your help in following case. i have table ChartData in that table
Need help with the following. I am creating two different combinations of view/controllers that

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.