On 05/28/2017 11:54 AM, Michelle Konzack wrote:
On 2017-05-28 11:23:47 Adrian Klaver hacked into the keyboard:
On 05/28/2017 10:53 AM, Michelle Konzack wrote:

SELECT * FROM products WHERE category IN
     (SELECT categories.cat FROM categories WHERE
     categories.serial = products.category);

Because you are comparing categories.cat

ehm no

Actually yes:

SELECT categories.cat FROM categories WHERE
    categories.serial = products.category

is going to select categories.cat which is a varchar.

SELECT * FROM products WHERE category IN ...

is asking to select all fields from where the products.category field is in the output of the above sub-select, which reduces down to products.category = categories.cat
or
integer = varchar. As the error message says , that is not possible.


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"


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;

My mistake, it should be:

SELECT categories.cat, manufacturer, p_name, p_images, p_desc
FROM products, categories WHERE products.category = categories.serial;


This is not working




--
Adrian Klaver
adrian.kla...@aklaver.com


--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Reply via email to