Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I wrote the first query below that I was hopeing to give me the exact same results that the 2nd query does, but it seems there is one recrod different:

    SELECT     DocumentSourceName
     FROM         dbo.DocumentSource
     WHERE     (DocumentSourceName NOT IN
                      (SELECT     DocumentSourceName
                        FROM          dbo.DocumentSource AS DocumentSource_1
                        WHERE      (DocumentSourceName LIKE 'ZZ%')))

Versus

    SELECT     TOP (100) PERCENT f.FacilityName, ds.DocumentSourceName, ds.DocumentSourceNotes
    FROM         dbo.DocumentSource AS ds INNER JOIN
                  dbo.Facility AS f ON ds.DocumentSourceFacility = f.FacilityID
    WHERE     (ds.DocumentSourceName NOT LIKE 'ZZ%') AND (ds.DocumentSourceInactive = 0)

So is it because of the "Top 100 percent" that I think its the same as the '*' or its because I have the "AND" in the "Where" Clause? Please advice. Thanks

share|improve this question

closed as off-topic by Paul White, RolandoMySQLDBA, Mark Storey-Smith, Max Vernon, Aaron Bertrand Jul 14 at 20:23

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Too localized - this could be because your code has a typo, basic error, or is not relevant to most of our audience. Consider revising your question so that it appeals to a broader audience. As it stands, the question is unlikely to help other users (regarding typo questions, see this meta question for background)." – Paul White, RolandoMySQLDBA, Mark Storey-Smith, Max Vernon, Aaron Bertrand
If this question can be reworded to fit the rules in the help center, please edit the question.

2  
Since your WHERE clauses are different, that is the most likely cause of different results. "TOP 100 PERCENT" has no effect; the results would be the same if it were excluded. –  dartonw Jul 2 at 22:06
    
@dartonw Thanks you for the clarifying this, as it puzzled me when I saw Top and the 100, then its the same as SELECT *. I will check the filtering in the Where clause, thanks again. –  Mary Jul 3 at 16:45

1 Answer 1

up vote 1 down vote accepted

The TOP does nothing - based on the fact that it's "100%".

The first query is essentially the same as: WHERE (ds.DocumentSourceName NOT LIKE 'ZZ%'), but the second has more filters...

share|improve this answer
    
Thanks for your reply, I will have to know the data better to judge why they added this filter that I wasn't thinking of. –  Mary Jul 3 at 16:43

Not the answer you're looking for? Browse other questions tagged or ask your own question.