Re: [GENERAL] SELECT statement with sub-queries
От | Adrian Klaver |
---|---|
Тема | Re: [GENERAL] SELECT statement with sub-queries |
Дата | |
Msg-id | efaf1e34-30a4-40bc-0a51-68b03fc134d9@aklaver.com обсуждение исходный текст |
Ответ на | Re: [GENERAL] SELECT statement with sub-queries (Michelle Konzack <linux4michelle@gmail.com>) |
Список | pgsql-general |
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.klaver@aklaver.com
В списке pgsql-general по дате отправления: