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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:19:44+00:00 2026-05-26T04:19:44+00:00

I have a query composing of COALESCE syntax. the COALESCE syntax simply find the

  • 0

I have a query composing of COALESCE syntax. the COALESCE syntax simply find the Audited Date of a file. On my WHERE statement, I just want to output the Audited File base from the AuditDate alias field but i doesn’t work. Here is my query.

SELECT COALESCE(qua.starttime, prd.starttime) AS `AuditDate`,
       prd.employeeno AS `EmployeeNo`,
       prd.starttime AS `StartTime`,
       prd.endtime AS `EndTime`
  FROM production prd
  LEFT JOIN qualityaudit qua
    ON prd.id=qua.id
 WHERE `AuditDate` BETWEEN '2011-10-01 00:00:00' AND '2011-10-01 23:59:59';

Can anyone help me on how should I get this query correct?

  • 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-26T04:19:44+00:00Added an answer on May 26, 2026 at 4:19 am

    Your query need to be like this

    SELECT COALESCE(qua.starttime, prd.starttime) AS `AuditDate`,
           prd.employeeno AS `EmployeeNo`,
           prd.starttime AS `StartTime`,
           prd.endtime AS `EndTime`
      FROM production prd
      LEFT JOIN qualityaudit qua
        ON prd.id=qua.id
     WHERE COALESCE(qua.starttime, prd.starttime) BETWEEN '2011-10-01 00:00:00' AND '2011-10-01 23:59:59';
    

    for your situation you can’t use the alias that came from a result of a function as query criteria in WHERE clause (see http://dev.mysql.com/doc/refman/5.0/en/problems-with-alias.html). But you can use the alias to search in HAVING clause, as MySQL 5.0.2 and up permit HAVING clause to refer to any column or alias named in a select_expr in the SELECT list or in outer subqueries, and to aggregate functions, like

    SELECT COALESCE(qua.starttime, prd.starttime) AS `AuditDate`,
           prd.employeeno AS `EmployeeNo`,
           prd.starttime AS `StartTime`,
           prd.endtime AS `EndTime`
      FROM production prd
      LEFT JOIN qualityaudit qua
        ON prd.id=qua.id
     HAVING `AuditDate` BETWEEN '2011-10-01 00:00:00' AND '2011-10-01 23:59:59';
    

    both have same result

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

Sidebar

Related Questions

I have query to show the table like this: but I want to PIVOT
Have this query: SELECT HOUR( DATE ) AS hr, COUNT( * ) AS cnt
I have MongoJS query call: db.users.find({username:eleeist},function(err, docs) { console.log(docs); }); The docs variable looks
I have a query with over 500,000 rows of data in the output. I
I have val maxId = new ObjectId(...) and I want to query something like
I have a database from which I want to query and display only that
I have an index problem with my order by statement. I have this query
I have query with two MtM relations: $em = $this->getEntityManager(); $qb = $em->createQueryBuilder(); $qb
I have query table copyQuery which has Soil Condition has one of the columns,
I have query like this : SELECT EXTRACT(MONTH FROM d.mydate) AS synmonth, SUM(apcp) AS

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.