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 |
Firemaple
Starting Member
14 Posts |
Posted - 2007-06-21 : 12:41:20
|
With the following query.. i should get all rows from the TBLANALYST table even if there are not matches...right?-----------------------SELECT TBLANALYST.usw_number, TBLANALYST.ANALYST_LAST_NAME, TBLANALYST.ANALYST_FIRST_NAME,TBLANALYST.SUPERVISOR_USW,TBLQADATA.QADATE, TBLQADATA.QAADDITIONALCOMMENT FROM TBLANALYST LEFT JOIN TBLQADATA ON (TBLQADATA.AGENTID = TBLANALYST.USW_NUMBER)WHERE TBLQADATA.QADATE BETWEEN '6/1/2007' AND '6/20/2007'ORDER BY TBLANALYST.USW_NUMBER,TBLQADATA.QADATE------------I'm probably doing something wrong... but i can put in LEFT JOIN, RIGHT JOIN, INNER JOIN,etc... and I always get the same results. any ideas? |
|
cvraghu
Posting Yak Master
187 Posts |
Posted - 2007-06-21 : 13:04:13
|
The WHERE clause would restrict your results. Make it part of Left join to get all records. LEFT JOIN TBLQADATA ON (TBLQADATA.AGENTID = TBLANALYST.USW_NUMBER)WHERE AND TBLQADATA.QADATE BETWEEN '6/1/2007' AND '6/20/2007' |
 |
|
Ifor
Aged Yak Warrior
700 Posts |
Posted - 2007-06-21 : 13:07:44
|
Move conditions on TBLQADATA to the ON Clause.SQL starts evaluating a query by:1. doing the JOINs.2. adding any outer rows in JOINs.3. applying the WHERE clause....This means that any conditions on TBLQADATA in the WHERE clause will effectively give an INNER JOIN. |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|