Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Filtering records in the FROM clause vs the WHERE clause

Posted on 2013-10-25
Medium Priority
Last Modified: 2013-10-25
I have a report that needs to pull records that are equal to S, R, or M.

So I need to pull records from OD_RECORD_TYPE = S,R,M

1. How do I write that in either section
2.......and does either affect the results since I will need these records for various parts of the report for several columns of data.
Question by:ruavol2
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
LVL 66

Accepted Solution

Jim Horn earned 1400 total points
ID: 39600313
2.  No, it doesn't affect the execution of the query.

1. Either of the below works, <air code, so making a few assumptions>
SELECT goo, foo, boo
FROM YourTable

SELECT,,, sot.wahoo
FROM YourTable yt
   INNER JOIN SomeOtherTable ON yt.ID = sot.ID AND sod.ODS_RECORD_TYPE IN ('S', 'R', 'M') 

Open in new window

LVL 66

Assisted Solution

by:Jim Horn
Jim Horn earned 1400 total points
ID: 39600319
>I have a report that needs to pull records that are equal to S, R, or M.
You'll want to expand on this.  
*  If it always does this, it can be hard-coded into the T-SQL that is the data source for the data set behind your report.
*  If this will be a user-selectable parameter value, then you'll want to set it up in SSRS as such.
LVL 101

Assisted Solution

mlmcc earned 600 total points
ID: 39600376
SO long as you are using inner joins it doesn't matter.

If you are using an outer join it can make a difference, particularly with Crystal

Modifying jimhorn's example above
SELECT,,, sot.wahoo
FROM YourTable yt
   LEFT OUTER JOIN SomeOtherTable ON yt.ID = sot.ID AND sod.ODS_RECORD_TYPE IN ('S', 'R', 'M')  

Open in new window

That will return all records from YourTable with a matching record that has an S, R, or M in the ODS_Record_Type field.  It will also return records from YourTable that don't have a matching record.

If you do it in the where clause the join is treated as INNER so only records from YourTable with a matching record will be returned.


Author Closing Comment

ID: 39600517
That took care of it....gotta love
Its like a beatiful woman except much easier to deal with........!
LVL 66

Expert Comment

by:Jim Horn
ID: 39600534
^^^  Dude, don't do that.  I had coffee in my mouth when I read the above line, and nearly sprayed.

Thanks for the grade.  Good luck with your project.  -Jim

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question