Re: SELECT statement with sub-queries

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Michelle Konzack <linux4michelle(at)gmail(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: SELECT statement with sub-queries
Date: 2017-05-28 19:22:07
Message-ID: CAKFQuwar_X8crrfeiCxva-zbUvBrNbN-YTT2Jkm1wMuh3ZskCg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sun, May 28, 2017 at 11:54 AM, Michelle Konzack <linux4michelle(at)gmail(dot)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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2017-05-28 20:15:57 Re: SELECT statement with sub-queries
Previous Message Neil Anderson 2017-05-28 19:13:36 Re: Help with terminology to describe what my software does please?