I've written a program with 2 views. but, I'm getting the error msg: Ambiguous column name 'b_id'. And, I need the b_id in the result. What can I do?
The code is as follows:
--view for all store managers with b_id and jobtitle
CREATE VIEW storemanagers
AS
SELECT b_id, jobTitle,e_firstname,e_middlename,e_lastname
FROM Employee
WHERE jobTitle='Store Manager'
----view for employee in each branch
CREATE VIEW employee_perbranch
AS
SELECT b_id, COUNT(*) AS 'Employee_count'
FROM Employee
GROUP BY b_id
--Procedure for listing store managers who manage a branch with more than 8 employees
SELECT*
FROM employee_perbranch
SELECT e_firstname, e_middlename, e_lastname, Employee_count,b_id
FROM storemanagers sm, employee_perbranch eb, Branch b
WHERE b.b_id=sm.b_id
AND eb.b_id=b.b_id
AND eb.Employee_Count >8
You should specify an alias for b_id
column from SELECT e_firstname, e_middlename, e_lastname, Employee_count,b_id
, either b.b_id
or sm.b_id
as it's present in both views.