I have two tables. Table Employees:
EmployeeID (employees) LastName (employees) FirstName (employees)
1 Davolio Nancy
And Table Orders:
OrderID (orders) CustomerID (orders) EmployeeID (orders)
10248 90 5
10278 45 1
10238 47 1
I redacted the full listing because it's hundreds of rows.
In the table Employees, the EmployeeID can uniquely identify an employee, meaning it will not repeat in the Employee table. However in the Table 'Order' The employeeID can repeat several times because an employee can sell help with many orders.
Anyway, I can see here that in the Orders table, an employeeID will repeat several times, which means I need to use COUNT(EmployeeID)>=2 somewhere in my MySQL code.
This is what I'd like:
EmployeeID Number of Orders
1 2
As you can see, the EmployeeID shows up twice in the "orders" table. So he sold 2 items, and it links to his 1 Employee ID.
So this is what I tried:
SELECT EmployeeID, COUNT(EmployeeID) FROM
employees A inner join
orders B
ON (A.EmployeeID=B.EmployeeID)
WHERE COUNT(B.EmployeeID >=2)
This is the output:
Error: Column 'EmployeeID' in field list is ambiguous — ERROR CODE 1052
I'm not sure how I would get this result in this scenario.