Mntfr Mntfr - 1 month ago 8
SQL Question

My query says that my column does not exist

This works but it returns all the data and I don't need that.

select *
from
`sec_permission` a
INNER JOIN
`sec_role_permission` b
on a.permission_id = b.permission_id
INNER JOIN
`sec_role` c
on b.role_id = c.`role_id`;


but when I specify the data

select `sec_permission`.`name`, `sec_role`.`name`
from
`sec_permission` a
INNER JOIN
`sec_role_permission` b
on a.permission_id = b.permission_id
INNER JOIN
`sec_role` c
on b.role_id = c.`role_id`;


it returns the message
Unknown column 'sec_permission.name' in 'field list
.
The column does exist.

Answer

When you assign a table alias, you have to use that when referring to the table. Since you assign the alias a to sec_permission, you have to use a.name, not sec_permission.name.

Comments