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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:39:27+00:00 2026-05-17T01:39:27+00:00

How to use grouping correctly in this query: $sQuery = SELECT id,DATE(A.Inspection_datetime) AS Date,

  • 0

How to use grouping correctly in this query:

$sQuery = "SELECT id,DATE(A.Inspection_datetime) AS Date,
                              A.Model, COUNT(A.Serial_number) AS Qty,
                              B.name
                      FROM inspection_report AS A
                      LEFT JOIN Employee AS B
                      ON A.NIK=B.NIK
                      GROUP BY Date, B.name".$sWhere.$sOrder.$sLimit;

i’m really new in concatenation.

  • 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-17T01:39:27+00:00Added an answer on May 17, 2026 at 1:39 am

    You need to GROUP BY both ‘id’ and ‘A.Model’ too, at least in most SQL DBMS (MySQL has laxer rules in this area). You need GROUP BY to come after the WHERE clause and before the ORDER BY clause. Hence:

    $sGroupBy = " GROUP BY id, Date, A.Model, B.Name ";
    $sQuery = "SELECT id,DATE(A.Inspection_datetime) AS Date,
                              A.Model, COUNT(A.Serial_number) AS Qty,
                              B.name
                      FROM inspection_report AS A
                      LEFT JOIN Employee AS B
                      ON A.NIK=B.NIK " .
                      $sWhere.$sGroupBy.$sOrder.$sLimit;
    

    Note that you must make sure there are spaces to separate the various clauses that you concatenate together; I added a space at each end of $sGroupBy (and after B.NIK) to make sure that part was OK.

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

Sidebar

Related Questions

Most programming languages use parentheses for grouping subexpressions. In Aklo, I'm using square brackets
I just looking how to use LINQ for grouping a list. Class Item Public
I use DevExpress v10.2.3 grouping gridview with asp.net mvc 4. I can get datas
use the [] symbol in the name of the form field you are submitting
In Perl, how can I use one regex grouping to capture more than one
Here is the problem. I need to transform this query to get the right
We use grouping to display master-detail report. If there are only nulls in a
I'm trying to use Linq expressions to construct a query, and am stuck trying
I use the grouping feature in a jqGrid. But I want to display the
Use Case Show a photo uploaded by the user in a square box with

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.