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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:19:09+00:00 2026-05-28T05:19:09+00:00

SELECT id,name,SUM(`lsa`) AS lst FROM table_a AS sn, table_b AS fb WHERE sn.uid=fb.uid AND

  • 0
SELECT id,name,SUM(`lsa`) AS lst FROM 
    table_a AS sn,
    table_b AS fb 
WHERE sn.uid=fb.uid 
  AND COUNT(`lsa`)=6 
GROUP BY sn.uid 
ORDER BY SUM(`lsa`)

I have a query like this one, apparently the AND COUNT(lsa)=6 bit isn’t valid syntax. I’m quite lost.

What I’d like to achieve is a list, ordered by the sum of lsa, grouped by uid, only if there are 6 entries for that uid, i.e. in that “group”. How am I supposed to do that?

  • 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-28T05:19:09+00:00Added an answer on May 28, 2026 at 5:19 am

    It is valid to filter by aggregates but that needs to go into the HAVING clause, not the WHERE so use

    SELECT id,
           name,
           SUM(`lsa`) AS lst
    FROM   table_a AS sn
           JOIN table_b AS fb
             ON sn.uid = fb.uid  /*Using Explicit Join syntax*/
    GROUP  BY sn.uid,            /*And avoiding MySQL GROUP BY extension*/
              id,
              name
    HAVING COUNT(`lsa`) = 6
    ORDER  BY SUM(`lsa`)  
    

    instead.

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

Sidebar

Related Questions

I have this query: SELECT p.text,se.name,s.sub_name,SUM((p.volume / (SELECT SUM(p.volume) FROM phrase p WHERE p.volume
This is My Query : SELECT user,name,SUM(price) FROM $tableName WHERE faktor='1' GROUP BY user
I have this script: select name,create_date,modify_date from sys.procedures order by modify_date desc I can
Let's say I have SELECT name FROM table which gives me something like foo
I have a SQL-statement like this: SELECT name FROM users WHERE deleted = 0;
Here is sample query SELECT name, sum(SELECT id FROM mytable WHERE cond='1' and cond2='2')
Is there any way to do something like this: select Name, sum(Exceptions) exceptions from
I want to make this query on Symfony/Propel SELECT folders.NAME, COUNT(documents.NAME), COUNT(files.idfiles), SUM(files.size) FROM
I have this SQL: select o.prod_id, SUM(o.[count]) as [count] into #otgr from otgr o
I have the following query in access 2003 mdb. SELECT Company.Name, Company.Address, Place.Name_of_Place, Sum(Income.Value)

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.