Re: [GENERAL] SELECT statement with sub-queries - Mailing list pgsql-general

From David G. Johnston
Subject Re: [GENERAL] SELECT statement with sub-queries
Date
Msg-id CAKFQuwar_X8crrfeiCxva-zbUvBrNbN-YTT2Jkm1wMuh3ZskCg@mail.gmail.com
Whole thread Raw
In response to Re: [GENERAL] SELECT statement with sub-queries  (Michelle Konzack <linux4michelle@gmail.com>)
List pgsql-general
On Sun, May 28, 2017 at 11:54 AM, Michelle Konzack <linux4michelle@gmail.com> wrote:

I want to replace in the output the numerical ID from "products.category"
with the value of "categories.cat", where the "products.category" match
the "categories.serial"

​Then go and read the first response in this thread, ​Amitabh Kant's, and confirm it works or say why it does not.  Personally I prefer "products JOIN categories ON/USING" but that is style and the "FROM products, categories WHERE" formulation will give the correct answer.

The syntax error in your original message is, like others have said, because "==(int, int)" is not a known operator.

And typically one writes:  "EXISTS (correlated subquery)" instead of "IN (correlated subquery)".  But if you want to replace a column in the output a predicate subquery (WHERE clause) that effectively implements a semi-join (only return results from one table) will not help you since you cannot actually refer to any of the columns in the subquery in the main query.  You need an actual join to do that.  IOW, writing "FROM products WHERE" when the output value you want is on the category table isn't going to help you.

David J.

pgsql-general by date:

Previous
From: Neil Anderson
Date:
Subject: Re: [GENERAL] Help with terminology to describe what my software does please?
Next
From: Adrian Klaver
Date:
Subject: Re: [GENERAL] SELECT statement with sub-queries