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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:28:12+00:00 2026-05-26T00:28:12+00:00

I have a query that pulled out the report depends on Audit Date, but

  • 0

I have a query that pulled out the report depends on Audit Date, but I’m very confuse on how the GROUP command is not working on what I’m expecting for the output.

Here is my queries,

SELECT prd.fldemployeeno `EmployeeNo`,
       prd.fldorderid `OrderNo`,
       prd.fldstarttime `TimeProcessed`,
       COUNT(qua.seqid) `ErrorCount`,
       COALESCE(qua.fldstarttime,(SELECT fldstarttime FROM tblproductionitl p
                                   WHERE (p.fldglobalid = prd.fldglobalid)
                                     AND p.fldprojectgroup=prd.fldprojectgroup
                                     AND p.fldstarttime > prd.fldstarttime
                                     AND prd.fldemployeeno != p.fldemployeeno
                                   LIMIT 0,1)) AS `AuditDate`
  FROM tblproductionitl prd
 INNER JOIN tblisauditeditl aud
    ON prd.fldglobalid=aud.fldid
  LEFT JOIN tblqualityaudit qua
    ON prd.fldglobalid=qua.fldid
   AND prd.fldstarttime=qua.fldprodstarttime
 GROUP BY prd.fldemployeeno,prd.fldorderid
 HAVING `AuditDate` BETWEEN '2011-10-04 00:00:00' AND '2011-10-04 23:59:59'
 ORDER BY `AuditDate`

And the output of this is

+-------------+---------------+---------------------+------------+---------------------+
| EmployeeNo  |   OrderNo     | TimeProcessed       | ErrorCount |  AuditDate          |
+-------------+---------------+---------------------+------------+---------------------+
| PSAA50577   | 20110930n01   | 2011-10-04 10:41:23 |   3        | 2011-10-04 10:44:07 |   
| PSAA50576   | 20111003n01   | 2011-10-03 11:39:52 |   1        | 2011-10-04 10:58:48 |
| PSAA50515   | 20110930n01   | 2011-10-04 10:44:07 |   1        | 2011-10-04 11:12:03 |
| PSAA50577   | 20111003n02   | 2011-10-03 12:22:33 |   1        | 2011-10-04 16:47:16 |
| PSAA50577   | 20110930n10   | 2011-10-01 18:27:09 |   1        | 2011-10-04 18:29:29 |
+-------------+---------------+---------------------+------------+---------------------+

And then I have removed the prd.fldorderid in the GROUP command so that the report will be grouped base from EmployeeNo only. But the output returns only 1 row instead of three. Please see below query and output.

SELECT prd.fldemployeeno `EmployeeNo`,
       prd.fldorderid `OrderNo`,
       prd.fldstarttime `TimeProcessed`,
       COUNT(qua.seqid) `ErrorCount`,
       COALESCE(qua.fldstarttime,(SELECT fldstarttime FROM tblproductionitl p
                                   WHERE (p.fldglobalid = prd.fldglobalid)
                                     AND p.fldprojectgroup=prd.fldprojectgroup
                                     AND p.fldstarttime > prd.fldstarttime
                                     AND prd.fldemployeeno != p.fldemployeeno
                                   LIMIT 0,1)) AS `AuditDate`
  FROM tblproductionitl prd
 INNER JOIN tblisauditeditl aud
    ON prd.fldglobalid=aud.fldid
  LEFT JOIN tblqualityaudit qua
    ON prd.fldglobalid=qua.fldid
   AND prd.fldstarttime=qua.fldprodstarttime
 GROUP BY prd.fldemployeeno
 HAVING `AuditDate` BETWEEN '2011-10-04 00:00:00' AND '2011-10-04 23:59:59'
 ORDER BY `AuditDate`

And the output for this query is:

+------------+--------------+---------------------+--------------+---------------------+
| EmployeeNo |  OrderNo     | TimeProcessed       | ErrorCount   |  AuditDate          |
+------------+--------------+---------------------+--------------+---------------------+
| PSAA50576  |  20111003n01 | 2011-10-03 11:39:52 | 1            | 2011-10-04 10:58:48 |
+------------+--------------+---------------------+--------------+---------------------+

Can anyone help me to analyze this on how only 1 row returned in second query and on how could I group the output base from Employee no.

  • 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-26T00:28:13+00:00Added an answer on May 26, 2026 at 12:28 am

    You should check the way you are grouping, from MySQL doc:

    MySQL extends the use of GROUP BY so that the select list can refer to
    nonaggregated columns not named in the GROUP BY clause. This means
    that the preceding query is legal in MySQL. You can use this feature
    to get better performance by avoiding unnecessary column sorting and
    grouping. However, this is useful primarily when all values in each
    nonaggregated column not named in the GROUP BY are the same for each
    group. The server is free to choose any value from each group, so
    unless they are the same, the values chosen are indeterminate.
    Furthermore, the selection of values from each group cannot be
    influenced by adding an ORDER BY clause. Sorting of the result set
    occurs after values have been chosen, and ORDER BY does not affect
    which values the server chooses

    Edit to explain. Given this example:

      SELECT column1
           , column2
    GROUP BY column1
    

    If the table can have different column2 given one value of column1 this is unsafe because anytime you execute the query you could get a different value of column2.
    In your subquery you are doing this and you should rewrite the query to avoid it.

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

Sidebar

Related Questions

I have a query that works on Postgresql 7.4 but not on Postgresql 8.3
I have a query that I pulled from ms sql 2000 and plugged into
I am using in C# MYsql .I have query that works if I run
I have a query that is dynamically built after looking up a field list
I have a query that originally looks like this: select c.Id, c.Name, c.CountryCode, c.CustomerNumber,
I have a query that looks like this: public IList<Post> FetchLatestOrders(int pageIndex, int recordCount)
I have a query that I'm executing from a .NET application to a SQL
I have a query that is currently using a correlated subquery to return the
I have a query that has 7 inner joins (because a lot of the
I have a query that runs super fast when executed in the sql editor

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.