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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:43:35+00:00 2026-06-11T19:43:35+00:00

I have a problem which I can’t really see how to work, I’ve tried

  • 0

I have a problem which I can’t really see how to work, I’ve tried some things based on findings on
Google, but to no avail. I hope someone here can help.

I have two tables (A and B), in table A I have some overview data which I want to select, and in table B I have details corresponding to table A (joined on two parameters), however the data in table B only needs to be summarized on number of rows.

I have this query:

SELECT s.CartID,
   s.Sender,
   s.Destination,
   s.CartType,
   s.SendDate,
   p.PackageID,
   p.CartID,
   COUNT(b.*) AS nRows
         FROM tblA s LEFT OUTER JOIN tblB p
         ON s.CartID = p.CartID AND s.SendDate = p.CartDate
         WHERE s.Client='3' AND s.SendDate BETWEEN '2012-09-01' AND '2012-09-07'

However, this only gives the following errror:

Incorrect syntax near ‘‘.*

I’ve also tried using this COUNT(b.PackageID) instead but then I get:

Column ‘tblA.CartID’ is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

I really don’t see how I’m going to get this data in one query.

Any help would be appreciated. 🙂

  • 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-11T19:43:36+00:00Added an answer on June 11, 2026 at 7:43 pm

    The error is telling you that you need to add all fields in the SELECT to either a GROUP BY or an aggregate like this:

    SELECT s.CartID,
       s.Sender,
       s.Destination,
       s.CartType,
       s.SendDate,
       p.PackageID,
       p.CartID,
       COUNT(p.*) AS nRows  -- I am guessing this should be p not b
    FROM tblA s 
    LEFT OUTER JOIN tblB p
      ON s.CartID = p.CartID 
      AND s.SendDate = p.CartDate
    WHERE s.Client='3' 
      AND s.SendDate BETWEEN '2012-09-01' AND '2012-09-07'
    GROUP BY s.CartID,
       s.Sender,
       s.Destination,
       s.CartType,
       s.SendDate,
       p.PackageID,
       p.CartID
    

    If you do not want to GROUP BY all of those fields, then you can also use a sub-query similar to this:

    SELECT s.CartID,
       s.Sender,
       s.Destination,
       s.CartType,
       s.SendDate,
       p.PackageID,
       p.CartID,
       p.Cnt as nRows
    FROM tblA s 
    LEFT OUTER JOIN
    (
      SELECT COUNT(*) cnt, CartID, PackageID, CartDate
      FROM tblB
      GROUP BY CartID, PackageID, CartDate
    ) p
      ON s.CartID = p.CartID 
      AND s.SendDate = p.CartDate
    WHERE s.Client='3' 
      AND s.SendDate BETWEEN '2012-09-01' AND '2012-09-07'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small problem which i can't seem to figure out. I tried
I have some problem with my open new window popup which it can read
I have a problem which seems simple, but I can't find an elegant solution
I have a problem which i can't seem to find the solution to. I
I have a small problem which i can't seem to solve myself. Look at
I have a strange problem which I can't fix: A field: private boolean[][][] gaps;
I have the following problem: I have a search box in which user can
Here is my problem : I have a list of messages which I can
I'm quite new to hibernate and have stumbled on this problem, which I can't
I have a problem which I don't really know how to solve. I have

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.