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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:55:16+00:00 2026-05-27T09:55:16+00:00

I have a query SELECT cd.signoffdate, min(cmp.dsignoff) as dsignoff FROM clients AS c LEFT

  • 0

I have a query

SELECT 
        cd.signoffdate,
        min(cmp.dsignoff) as dsignoff
      FROM clients AS c 
      LEFT JOIN campaigns AS cmp ORDER BY dsignoff;

If I want to have something like this built into the postgres query will it work and how do I do it

if the cd.signoffdate is empty it should take min(cmp.dsignoff) as dsignoff as the value and then order by this column, so in other words it should order by dsignoff and cd.signoffdate and tread it as one column, is this possible and how?

  • 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-27T09:55:16+00:00Added an answer on May 27, 2026 at 9:55 am

    Your query could look like this:

    SELECT c.client_id, COALESCE(c.signoffdate, min(cmp.dsignoff)) AS signoff
    FROM   clients c 
    LEFT   JOIN campaigns cmp ON cmp.client_id = c.client_id  -- join condition!
    GROUP  BY c.client_id, cd.signoffdate                     -- group by!
    ORDER  BY COALESCE(c.signoffdate, min(cmp.dsignoff));
    

    Or, with simplified syntax:

    SELECT c.client_id, COALESCE(c.signoffdate, min(cmp.dsignoff)) AS signoff
    FROM   clients c 
    LEFT   JOIN campaigns cmp USING (client_id)
    GROUP  BY 1, cd.signoffdate
    ORDER  BY 2;
    

    Major points:

    • Used alias c, but referenced as cd.
    • No join condition leads to cross join, probably not intended.
    • Missing GROUP BY.
    • I assume that you want to group by the primary key column of clients and call it client_id.
    • I also assume that client_id links the two tables together.
    • COALESCE() serves as fallback in case signoffdate IS NULL.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have query SELECT helpc.cid, COUNT(help.cid) AS children_count FROM air_help_category AS helpc LEFT JOIN
I have this query: SELECT page.id, revision.title, revision.number FROM page INNER JOIN revision ON
i have sql query select * from Roles Join Users On Roles.Role=Users.RoleId it return
I have this query: SELECT * FROM sample INNER JOIN test ON sample.sample_number =
I have this query: SELECT DISTINCT IM.EDIFICIOS_ID, TI.TITULAR FROM IMPORTACION IM INNER JOIN I_EDIFICIO
I have this query: SELECT * FROM bookmarks WHERE id=? ORDER BY title ASC,
I have this query: SELECT g.title, g.asin, g.platform_id, r.rank FROM games g INNER JOIN
I have a query: SELECT * FROM (SELECT COLA, COLB, COLC, COLD, ROW_NUMBER() OVER(ORDER
I have this query: SELECT p.id, r.status, r.title FROM page AS p INNER JOIN
I have a query select * from myTable ...and I want to wrap this

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.