Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
helixpoint
Constraint Violating Yak Guru
291 Posts |
Posted - 2014-11-06 : 12:17:06
|
I have 2 tablesEmployee and PositionsEmployeeidempidNamePositionempidposNameI want to do a select on employee and bring back one employee record and add a count of how many positions he hasDaveHelixpoint Web Developmenthttp://www.helixpoint.com |
|
AASC
Starting Member
24 Posts |
Posted - 2014-11-06 : 13:19:22
|
--Temporary table creationCREATE TABLE #employee( id INT,empid INT,name VARCHAR(100))CREATE TABLE #positions ( empid INT,Posname VARCHAR(200))--- dumpy data insert INSERT INTO #employeeSELECT 1, 1, 'Rocky'UNION ALL SELECT 2,200,'Sam'INSERT INTO #positions SELECT 1,'PM'UNION ALL SELECT 1,'BOP'UNIONSELECT 2, 'L'UNION SELECT 2, 'M'--- Query to select employee with count of positionsSELECT emp.id,emp.empid,emp.name ,COUNT(pos.Posname)FROM #employee emp INNER JOIN #positions pos ON emp.empid=pos.empidWHERE emp.name='rocky'GROUP BY emp.id,emp.empid,emp.name |
|
|
|
|
|
|
|