Volvox
Volvox

Reputation: 621

AdventureWorks SQL conflicting results issue

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.

UPDATE: These are my results:

Upvotes: 1

Views: 502

Answers (2)

Arion
Arion

Reputation: 31239

The only diffrents i can see is this:

where 
   e.Title like '%Sales Manager%'

And this:

Where 
 e.Title LIKE '%Manager%'
    AND
  e.Title LIKE '%Sales%'

The first query says that bring me all titles that has '%Sales Manager%' you can have for ex this output:

Account Sales Manager
some Sales Manager
Sales Manager something else

The second question says bring me all the titles that has '%Manager%' and '%Sales%' so you can for ex have:

Sales Account Manager
some Sales some Manager some 
Sales Manager some else thing
Manager Sales

And this join can not be corrent

INNER JOIN Person.Contact c
    ON e.EmployeeID = c.ContactID

Don't you mean:

INNER JOIN Person.Contact c
        ON e.ContactID= c.ContactID

Upvotes: 1

Andrey Gurinov
Andrey Gurinov

Reputation: 2885

The first query will match the rows where substring "Sales Manager" is present. But second one can match rows like "Managers of Sales Dep" as well. I mean the second doesn't care about positions of the words in the srting.

I believe that the results of first query is a subset of the results of second one.

UPDATE You use different columns in JOIN clause, so it's normal that you got different results.

Upvotes: 1

Related Questions