I must connect three table. My code works great with two tables but doesn't work with three table. I use PostgreSQL 9.4.9 in Debian.
Code with 2 tables (WORKS):
SELECT
manufactures.manufacturename
,products.productname
FROM products
INNER JOIN manufactures
ON manufactures.manufactureid=products.productmanufacturer;
Code with 3 tables (Doesn't works)
SELECT
manufactures.manufacturename
,products.productname
,languages.languagename
FROM products
INNER JOIN manufactures
ON manufactures.manufactureid=products.productmanufacturer
INNER JOIN languages
ON languages.languagename=products.productlanguage;
Error message
baza_testowa=# SELECT
baza_testowa-# manufactures.manufacturename
baza_testowa-# ,products.productname
baza_testowa-# ,languages.languagename
baza_testowa-# FROM products
baza_testowa-# INNER JOIN manufactures
baza_testowa-# ON manufactures.manufactureid=products.productmanufacturer
baza_testowa-# INNER JOIN languages
baza_testowa-# ON languages.languagename=products.productlanguage;
ERROR: operator does not exist: text = integer
LINE 9: ON languages.languagename=products.productlanguage;
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
Table "public.products"
Column | Type | Modifiers
---------------------+---------+--------------------------------------------------------------
productid | integer | not null default nextval('products_productid_seq'::regclass)
productmanufacturer | integer | not null
productname | text | not null
productlanguage | integer |
Indexes:
"products_pkey" PRIMARY KEY, btree (productid)
Table "public.manufactures"
Column | Type | Modifiers
-----------------+---------+----------------------------------------------------------------------
manufactureid | integer | not null default nextval('manufactures_manufactureid_seq'::regclass)
manufacturename | text | not null
Indexes:
"manufactures_pkey" PRIMARY KEY, btree (manufactureid)
Table "public.languages"
Column | Type | Modifiers
--------------+---------+----------------------------------------------------------------
languageid | integer | not null default nextval('languages_languageid_seq'::regclass)
languagename | text | not null
Indexes:
"languages_pkey" PRIMARY KEY, btree (languageid)
products.productlanguageis an integer. Is it really what you want that it is the same aslanguages.languagename?