Duplicate key name 'fk_ 1

Duplicate key name ‘fk_

SELECT U.*, UP.name
FROM units U
LEFT JOIN units UP ON U.parent_id = UP.id

Here is what the above code is Doing:
1. We’re selecting all the columns from the units table.
2. We’re joining the units table to itself, but we’re giving it an alias of UP.
3. We’re saying that we only want to join when the parent_id column in the units table is equal to the id column of the units table we aliased as UP.
4. We’re saying that even if there isn’t a row in the UP table that matches the parent_id in the units table, we still want that row to be returned.

Similar Posts