• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Help with large-ish SQL query with two sub queries

Here is my query:

Code:
SELECT TOP 100 PERCENT c.Empl_Nbr, c.Qlfn_Code as CurrentQlfn_Code, c.CDL, a.Qlfn_CodeDate as LastLE01, b.Qlfn_CodeDate as LastCDL1
FROM DVMS_Main as c,
 /*LE01 Query*/
 (
  SELECT DVMS_LicHist.Empl_Nbr, DVMS_LicHist.Qlfn_Code, max(DVMS_LicHist.EntryDate) as Qlfn_CodeDate
  FROM DVMS_LicHist
  WHERE DVMS_LicHist.Qlfn_Code = 'LE01'
  GROUP BY DVMS_LicHist.Empl_Nbr, DVMS_LicHist.Qlfn_Code
  /*ORDER BY DVMS_LicHist.Empl_Nbr*/
 ) as a,
 
 /*CDL1 Query*/
 (
  SELECT DVMS_LicHist.Empl_Nbr, DVMS_LicHist.Qlfn_Code, max(DVMS_LicHist.EntryDate) as Qlfn_CodeDate
  FROM DVMS_LicHist
  WHERE DVMS_LicHist.Qlfn_Code = 'CDL1'
  GROUP BY DVMS_LicHist.Empl_Nbr, DVMS_LicHist.Qlfn_Code
  /*ORDER BY DVMS_LicHist.Empl_Nbr*/
 ) as b
WHERE  c.Empl_Nbr = a.Empl_Nbr
 AND c.Empl_Nbr = b.Empl_Nbr
 AND c.Qlfn_Code = 'LE01'
 AND b.Qlfn_CodeDate >= a.Qlfn_CodeDate
 AND c.CDL IS NOT NULL
 AND c.CDL <> ' '
 AND c.CDL <> 'O'
 AND c.CDL <> 'C'
 AND c.CDL <> 'D'
 AND c.ActiveFlag = 'Y'
ORDER BY c.Empl_Nbr

I want to compare the columns LastLE01 and LastCDL1. As you may notice, I have the following like in my WHERE clause:

Code:
AND b.Qlfn_CodeDate >= a.Qlfn_CodeDate

However, is SQL joining on these? I want it to be treated as a compare statement, but is it treating it as a join? The goal is to output where c.Qlfn_Code = 'LE01' AND WHERE LastCDL1 >= LastLE01.

Thanks!
 
Looks like that should work fine for what you want it for.
Anytime you compare 2 table columns it'll be a join of some sort, but that really doesn't matter - its the same thing, its just filtering out rows you don't want.
 
select * from a, b where a.field = b.field

is for all intents and purposes the same thing as

select * from a join b on a.field = b.field

Depending on your particular RDMBS it's possible that they might have a slightly different execution plan, but the results should be the same.
 
Back
Top