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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:31:46+00:00 2026-05-23T14:31:46+00:00

I have a query reading a date from a parent/child relationship and i need

  • 0

I have a query reading a date from a parent/child relationship and i
need to group the records by the max of the date, from whichever
tables this comes. My query:

SELECT child.id as id, 
       MAX(pm.start), 
       MAX(membership.start),
       MAX(IFNULL(pm.start,membership.start)) AS start 
FROM   organisation child
LEFT JOIN organisation pmorg ON child.parent_organisation_id = pmorg.id
LEFT JOIN membership ON child.id = membership.organisation_id
LEFT JOIN membership pm ON pmorg.id = pm.organisation_id

WHERE child.id IN (1,3) AND /*just look at example records*/

    coalesce(pm.start,membership.start) IS NOT NULL AND
    ((membership.active = 1 AND membership.amount_paid > 0.00 ) OR
     (pm.active = 1 AND pm.amount_paid > 0.00))

GROUP BY child.id

My Output is strangely:

1       NULL                    2011-07-01 00:00:00 323031312d30372d30312030303a30303a3030
3       2011-07-01 00:00:00     NULL                323031312d30372d30312030303a30303a3030

I need that last column to be 2011-07-01 and I need both rows. Any
idea why max(coalesce()) doesn’t work? I’m running MySQL 5.1

  • 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-23T14:31:46+00:00Added an answer on May 23, 2026 at 2:31 pm

    Stupidly this query only breaks in PHPMyAdmin and works completely fine in mysql command line. So no issue here at all!

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

Sidebar

Related Questions

I'm really struggling with this query. I have 4 tables (http://oberto.co.nz/db-sql.png): Invoice_Payement, Invoice, Client
I have a query like this: SELECT TOP 1 ID, DATA, OTHERINF FROM MYTABLE
I have a query where I wish to retrieve the oldest X records. At
I have a query that originally looks like this: select c.Id, c.Name, c.CountryCode, c.CustomerNumber,
I have this query in sql server 2000: select pwdencrypt('AAAA') which outputs an encrypted
I have a query that looks like this: public IList<Post> FetchLatestOrders(int pageIndex, int recordCount)
I have a query on my database as such: SELECT * FROM expenses WHERE
I have a query that I'm executing from a .NET application to a SQL
I have an Oracle 10g table that contains a # of log records. This
I have a set of tables in MySQL like this (foreign keys referenced by

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.