From: | Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: SELECT statement with sub-queries |
Date: | 2017-05-28 18:23:47 |
Message-ID: | 54361d04-0498-970d-d8de-86b59c02e6cb@aklaver.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 05/28/2017 10:53 AM, Michelle Konzack wrote:
> On 2017-05-29 03:24:54 rob stone hacked into the keyboard:
>> You only need a single equals sign in SQL.
>>
>> SELECT * FROM products WHERE category IN
>> (SELECT categories.cat FROM categories WHERE
>> categories.serial = products.category);
>
> I have tried this too, but then I get:
>
> ERROR: operator does not exist: integer = character varying
> LINE 1: SELECT * FROM products WHERE category IN (SELECT categories....
> ^
>
> My sql file is:
>
> ----8<------------------------------------------------------------------
> DROP TABLE categories;
> DROP TABLE manufacturers;
> DROP TABLE products;
>
> CREATE TABLE categories (
> serial integer NOT NULL,
> cat varchar(40),
> );
>
> CREATE TABLE manufacturers (
> serial integer NOT NULL,
> m_name varchar(40),
> m_address varchar(200),
> m_images varchar(100),
> m_desc varchar(1000),
> );
>
> CREATE TABLE products (
> serial integer NOT NULL,
> category integer NOT NULL,
> manufacturer integer NOT NULL,
> p_name varchar(40),
> p_images varchar(100),
> p_desc varchar(10000),
> );
> ----8<------------------------------------------------------------------
>
> This is WHY I am puzzeling arround with the "integer" error.
Because you are comparing categories.cat which is a varchar to
products.category which is an integer. The above is crying out for
FOREIGN KEYS. For the time being I going to assume products.category is
a faux FK to categories.serial so;
SELECT * FROM products WHERE products.category = categories.serial;
>
>
--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | ml | 2017-05-28 18:24:43 | Re: SELECT statement with sub-queries |
Previous Message | ml | 2017-05-28 18:19:59 | Re: SELECT statement with sub-queries |