Lab-verifiedReproduced and fixed on PostgreSQL 17.12 · 2026-11-30 · container image postgres:17
SQLSTATE 42712 (duplicate_alias) means two items in the same query have the same reference name. When you list a table twice without aliases, both are called by the table name and PostgreSQL refuses the query.
The two common cases are a self-join and UPDATE ... FROM that repeats the table being updated.
01Self-join without table aliases
To show each employee with their manager, employees is joined to itself, but neither side has an alias. Both are named employees, so PostgreSQL cannot tell them apart.
Setup
CREATE TABLE employees (emp_id int PRIMARY KEY, name text, manager_id int);
INSERT INTO employees VALUES (1, 'Kim', NULL), (2, 'Lee', 1), (3, 'Park', 1);CREATE TABLE
INSERT 0 3SELECT employees.name, employees.name
FROM employees
JOIN employees ON employees.manager_id = employees.emp_id;ERROR: 42712: table name "employees" specified more than onceSELECT emp_id, name, manager_id FROM employees ORDER BY emp_id; emp_id | name | manager_id
--------+------+------------
1 | Kim |
2 | Lee | 1
3 | Park | 1
(3 rows)Each row has a manager_id that points to another row in the same table. Give the two sides different aliases (e for the employee, m for the manager): Lee and Park both show Kim as manager.
SELECT e.name AS employee, m.name AS manager
FROM employees e
JOIN employees m ON e.manager_id = m.emp_id
ORDER BY e.emp_id; employee | manager
----------+---------
Lee | Kim
Park | Kim
(2 rows)02UPDATE ... FROM repeats the table being updated
In PostgreSQL the target of UPDATE is already part of the query. Writing FROM products again adds a second products, which is a duplicate name. (Even with an alias it would become a join with every row, which is not what was meant here.)
Setup
CREATE TABLE products (product_id int PRIMARY KEY, category text, price numeric);
INSERT INTO products VALUES (1, 'pen', 1000), (2, 'pen', 1500), (3, 'note', 3000);CREATE TABLE
INSERT 0 3UPDATE products
SET price = price * 1.1
FROM products
WHERE products.category = 'pen';ERROR: 42712: table name "products" specified more than onceSELECT product_id, category, price FROM products ORDER BY product_id; product_id | category | price
------------+----------+-------
1 | pen | 1000
2 | pen | 1500
3 | note | 3000
(3 rows)The condition is on the same table, so FROM is not needed at all. UPDATE products SET price = price * 1.1 WHERE category = 'pen' updated 2 rows: 1000 → 1100.0, 1500 → 1650.0.
UPDATE products
SET price = price * 1.1
WHERE category = 'pen';
SELECT product_id, category, price FROM products ORDER BY product_id;UPDATE 2
product_id | category | price
------------+----------+--------
1 | pen | 1100.0
2 | pen | 1650.0
3 | note | 3000
(3 rows)FAQ
How do I fix 'table name specified more than once' in PostgreSQL?
Give every occurrence of the table its own alias, for example FROM employees e JOIN employees m ON e.manager_id = m.emp_id, and use the aliases in SELECT and ON.
Why does UPDATE ... FROM give 42712?
The table after UPDATE is already in the query. Do not list it again in FROM; put only other tables there, or drop FROM when the condition uses the same table.
Is a self-join allowed in PostgreSQL?
Yes. A table can appear any number of times as long as each occurrence has a different alias.
How we verify
Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.
lab_a and lab_b are ordinary roles created for the test, each owning a schema of the same name; postgres is the superuser. PostgreSQL 17.12