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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:58:15+00:00 2026-06-06T17:58:15+00:00

Anyone knows how to perform such query in Postgresql? SELECT * FROM tabA WHERE

  • 0

Anyone knows how to perform such query in Postgresql?

SELECT * 
FROM tabA 
WHERE NOT EXISTS (
    SELECT * 
    FROM tabB 
    WHERE tabB.id = tabA.id
)

When I execute such query, postgresql complains “ERROR: Greenplum Database does not yet support that query.”

EDIT: And how about this one:

SELECT * 
FROM tabA 
WHERE NOT EXISTS (
    SELECT * 
    FROM tabB WHERE tabB.id = tabA.id AND tabB.id2 = tabA.id2
)

EDIT:

I tested in postgresql 8.2.15 for the 4 answers provided by @ypercube. Conclusions are:


1) The first does not work in this version of postgresql, as I said above in the question. The error message can be found there too.


2) For the other three answers, the execution speed is: (3)LEFT JOIN > (4)EXCEPT >> (2)NOT IN.
Specifically, for queries that have the same syntax, (3)LEFT JOIN takes about 5580ms, (4)EXCEPT takes about 13502ms, and (2)NOT IN takes more than 100000 (In fact I did not wait util it finished).

Is there any particular reasons for NOT IN clause to be so slow?

Cheng

  • 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-06-06T17:58:18+00:00Added an answer on June 6, 2026 at 5:58 pm

    There are 3 (main) ways to do this kind of query:

    1. NOT EXISTS correlated subquery

    2. NOT IN subquery

    3. LEFT JOIN with IS NULL check:

    You found that the first way does work in Greenplum. @Marco and @juergen provided the 2nd way. Here’s the 3rd one, it may bypass Greenplum’s limitations:

    SELECT tabA.* 
    FROM 
        tabA 
      LEFT JOIN 
        tabB 
          ON  tabB.id = tabA.id 
          AND tabB.id2 = tabA.id2
    WHERE tabB.id IS NULL ;
    

    This (4th way) also works in Postgres (which supports EXCEPT operator):

    SELECT a.*
    FROM a
    WHERE id IN
          ( SELECT id
            FROM a
          EXCEPT
            SELECT id
            FROM b
          ) ; 
    

    Tested in SQL-Fiddle (that all 4 work in Postgres).

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

Sidebar

Related Questions

does anyone knows how to perform such calculations Example: O(n^2) + THETA(n) + OMEGA(n^3)
I was wondering whether anyone knows of any tools available that perform the task
Anyone knows why my sql query doesn't work after using a try catch function?
Anyone knows the equivalent of a label control in an android device? Text box
Anyone knows a good way to use http live streaming tools on non-Mac platforms?
Anyone knows a simple JavaScript library implementing the UNZIP algorithm? No disk-file access, only
Anyone knows of some good Unicode tutorials with examples in C? I have to
Anyone knows the difference between System.Diagnostic.Trace and System.Diagnostic.TraceSource classes? I've been using Trace for
anyone knows any java utility method that would convert windows paths to DOS 8.3
Anyone knows how i can implement re-arrangable divs (Drag the divs around on the

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.