Extracting data from the Synergetic database
Extracting data from the Synergetic database
Extracting data from the Synergetic database
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Advanced Microsoft Query and SQL examples<br />
<strong>Extracting</strong> <strong>data</strong> <strong>from</strong> <strong>the</strong> <strong>Synergetic</strong> <strong>data</strong>base<br />
Example 3 - All parents who are also staff members (primary or spouse)<br />
Query<br />
SELECT DISTINCT<br />
StudentContactMailName, StudentContactAddressFull<br />
FROM vStudentContactAddress<br />
LEFT JOIN Community ON (<br />
StudentContactID = Community.ID)<br />
WHERE EXISTS (SELECT * FROM Constituencies<br />
WHERE vStudentContactAddress.StudentContactID = Constituencies.ID<br />
AND ConstitCode = '@STF')<br />
OR EXISTS (SELECT * <strong>from</strong> Constituencies<br />
Points to note:<br />
WHERE SpouseID = Constituencies.ID<br />
AND ConstitCode = '@STF')<br />
• DISTINCT specifies that only unique rows can appear in <strong>the</strong> returned <strong>data</strong> set. Null values are<br />
considered equal for <strong>the</strong> purposes of this keyword.<br />
• LEFT JOIN specifies that all rows <strong>from</strong> <strong>the</strong> left table that are not meeting <strong>the</strong> join condition are<br />
included in <strong>the</strong> results set, and output columns <strong>from</strong> <strong>the</strong> o<strong>the</strong>r table are set to NULL in addition<br />
to all rows returned by <strong>the</strong> inner join.<br />
• INNER JOIN specifies that all records that meet <strong>the</strong> join condition on both sides are included<br />
in <strong>the</strong> results set.<br />
Version 60 Page 6-67