I’m working with the AdventureWorks example DB – we’re running SQL Server 2008R2, so I assume that’s the edition of AdventureWorks (I have read-only access). I’m trying to get a list of sales managers so that I can then determine a couple employee/manager relationships.
I’m getting two sets of three differently named people, with the same job title, with their CurrentFlag set to 1 (active) with slightly different queries. I do notice that one result group has the same contactID and employeeID, but I’m not sure what this may indicate.
So the question is: Why am I getting completely different results with these two queires? I would think I’d get six results for each – the queries are matching employee table Titles.
-
SQL Query 1:
select c.FirstName, c.LastName, c.ContactID, e.EmployeeID, e.Title, c.Title, e.CurrentFlag from Person.Contact c inner join HumanResources.Employee e on c.ContactID = e.ContactID where e.Title like '%Sales Manager%' -
SQL Query 2:
SELECT e.EmployeeID, (c.FirstName + ' ' + c.LastName) as 'First Name and Last Name', e.Title FROM HumanResources.Employee e INNER JOIN Person.Contact c ON e.EmployeeID = c.ContactID Where e.Title LIKE '%Manager%' AND e.Title LIKE '%Sales%' ORDER BY e.EmployeeID;
UPDATE: These are my results:
-
SQL Query 1:
------- ------- ---- --- ---------------------------- ---- -- Stephen Jiang 1011 268 North American Sales Manager NULL 1 Amy Alberts 1013 284 European Sales Manager NULL 1 Syed Abbas 1012 288 Pacific Sales Manager Mr. 1 -
SQL Query 2:
--- --- ----------- ---------------------------- --- -- 268 268 Gary Drury North American Sales Manager Mr. 1 284 284 John Emory European Sales Manager Mr. 1 288 288 Julie Estes Pacific Sales Manager Ms. 1
The only diffrents i can see is this:
And this:
The first query says that bring me all titles that has
'%Sales Manager%'you can have for ex this output:The second question says bring me all the titles that has
'%Manager%‘ and'%Sales%'so you can for ex have:And this join can not be corrent
Don’t you mean: