Skip to content

Instantly share code, notes, and snippets.

@dstndstn
Created August 12, 2013 18:11
Show Gist options
  • Select an option

  • Save dstndstn/6213419 to your computer and use it in GitHub Desktop.

Select an option

Save dstndstn/6213419 to your computer and use it in GitHub Desktop.
SubmitJob.aspx source
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Pragma" content="no-cache" />
<title>CasJobs</title>
<link href="cjobs.css" rel="stylesheet" />
<script type="text/javascript" src="scripts/submitjob.js"></script>
<script type="text/javascript" src="scripts/shortcut.js"></script>
<script type="text/javascript" language="JavaScript">
var queryIsRunning = false;
var editor;
var samplePreview;
var cm;
function completeQuery() {
if (queryIsRunning) {
document.getElementById('message').className = 'happy';
document.getElementById('message').innerHTML = 'Query complete!';
showExecButtons();
setEditorMid();
queryIsRunning = false;
}
}
function trmenu() {
if (window.frames['resultPane'].document.body.innerHTML.length < 15)
document.getElementById('menuRow').style.display = 'none';
else {
document.getElementById('menuRow').style.display = '';
setEditorMid();
}
}
function onSubmitQueryLoad() {
initEditor();
initSamplePreview();
resubmit = document.location.href.indexOf("resubmit") > -1 && document.getElementById('rsqry').innerHTML.length > 0; // || document.location.href.indexOf("sql") > -1;
loadSubmitPage();
window.onunload = saveSubmitPage;
if (document.getElementById('samples').style.display == 'block')
document.getElementById('sampCheck').checked = true;
editor.focus();
initHist();
window.onresize = windowResize;
setSamples();
initShortCuts();
}
function initShortCuts() {
shortcut.add("Ctrl+H", setEditorMid);
shortcut.add("Ctrl+J", maxQuery);
shortcut.add("Ctrl+K", maxResults);
shortcut.add("Ctrl+S", checksyntax);
shortcut.add("Ctrl+Q", submitQuickQuery);
shortcut.add("Ctrl+U", submitQuery);
shortcut.add("Ctrl+P", getplan);
shortcut.add("Enter", reindent, {
'propagate': true
});
}
function reindent() {
editor.indentLine(editor.getCursor().line);
}
function setSamples() {
var tddl = document.getElementById('targetDDL');
var context = tddl[tddl.selectedIndex].value;
var tmp = document.getElementById(context.toLowerCase() + "_samples");
if (!tmp)
tmp = document.getElementById("global_samples");
document.getElementById('samples').innerHTML = tmp.innerHTML;
}
var lastQry;
var rsThread = null;
var cm;
function windowResize() {
if (rsThread) {
clearTimeout(rsThread);
} else {
lastQry = editor.getValue();
editor.setValue('');
cm.style.height = '100%';
cm.style.width = 'auto';
}
rsThread = setTimeout(completeResize, 500);
}
function completeResize() {
var osh = cm.offsetHeight;
var osw = cm.offsetWidth;
cm.style.height = osh;
cm.style.width = osw;
editor.setValue(lastQry);
lastQry = null;
rsThread = null;
}
function initEditor() {
var qc = document.getElementById('queryCell');
editor = CodeMirror(qc, {
lineNumbers: true,
matchBrackets: true,
onCursorActivity: hfloats,
//tabMode: "shift",
tabMode: "indent",
mode: "text/x-tsql"
});
cm = qc.childNodes[0];
if (!cm.style) cm = qc.childNodes[1];
cm.style.height = '100%';
cm.style.width = 'auto';
cm.style.padding = '0 0 0 0';
cm.style.margin = '0 0 0 0';
cm.style.overflow = 'hidden';
cm.style.border = 'none';
windowResize();
//cm.style.height = cm.offsetHeight - 5;
}
function hfloats() {
hideFloats();
}
function initSamplePreview() {
var qc = document.getElementById('samplePreviewPane');
samplePreview = CodeMirror(qc, {
lineNumbers: false,
matchBrackets: false,
readOnly: true,
mode: "text/x-tsql"
});
}
</script>
<style type="text/css">
table
{
padding: 0 0 0 0;
margin: 0 0 0 0;
}
</style>
<script src="scripts/codemirror.js"></script>
<script src="scripts/tsql.js"></script>
</head>
<body style="padding: 0 0 0 0; margin: 0 0 0 0" onload="onSubmitQueryLoad();">
<form name="SubmitJob" id="SubmitJob" action="SubmitJob.aspx" method="post" target="_top"
style="padding: 0 0 0 0; margin: 0 0 0 0">
<textarea id="rsqry" style="display:none"></textarea>
<input type="hidden" id="queue" name="queue" value="1" style="display: none;" />
<table cellspacing="0" cellpadding="0" id="mostEverything" style="width: 100%; height: 100%">
<tr>
<td>
<style type="text/css">
img {
behavior: url("pngbehavior.htc");
}
</style>
<link rel="shortcut icon" href="favicon.ico"/>
<div id="div_title" style="background-image: url(img/sdss_back.jpg); background-position: right;
background-repeat: no-repeat; background-color: Black;">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr height="73">
<td>
<a href="http://www.sdss3.org">
<img border="0" style="width:73;height:60" src="img/sdss3_logo.png"></a></td>
<td height="73" width="100%">
<a href="default.aspx">
<img style="border-style: none" src="img/titlebar_left.png" height="73" width="247"></a></td>
<td style="text-align: right;">
&nbsp;
</td>
</tr>
</table>
</div>
<div id="div_nav">
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="width: 100%;">
<tr>
<td align="center">
<a target="_parent" href="Guide.aspx">Help</a></td>
<td width="60" align="center">
<a target="_parent" href="casjobscl.aspx">Tools</a></td>
<td align="center">
<a target="_parent" href="SubmitJob.aspx">Query</a></td>
<td align="center">
<a target="_parent" href="ViewJobs.aspx">History</a></td>
<td align="center">
<a target="_parent" href="MyDB.aspx">MyDB</a></td>
<td align="center">
<a target="_parent" href="TableImport.aspx">Import</a></td>
<td align="center">
<a target="_parent" href="Groups.aspx">Groups</a></td>
<td align="center">
<a target="_parent" href="Output.aspx">Output</a></td>
<td align="center">
<a target="_parent" href="ChangeDetails.aspx">Profile</a></td>
<td align="center">
<a target="_parent" href="admin.aspx">Queues</a></td>
<td align="center">
<a target="_blank" href="http://skyserver.sdss3.org">SkyServer</a></td>
<td align="center">
<a target="_parent" href="logout.aspx">Logout</a></td>
<td style="width: 100%;">
&nbsp;</td>
<td align="center" style="border-left: none;">
dstn
</td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td>
<table style="width: 100%">
<tr>
<th class="mover">
<a href="#" onmouseover="showqsnode('contextHelpDiv');" onmouseout="hideqsnode();">Context</a>
</th>
<th class="mover" style="white-space: nowrap">
<a href="#" onmouseover="showqsnode('tableHelpDiv');" onmouseout="hideqsnode();">Table
<span style="font-weight: normal" size="-2">(optional)</span></a>
</th>
<th class="mover" style="width: 100%">
<a href="#" onmouseover="showqsnode('taskNameHelpDiv');" onmouseout="hideqsnode();">
Task Name</a>
</th>
</tr>
<tr>
<td align="center">
<select name="targest" id="targetDDL" onchange="setSamples();">
<option >
MyDB
</option>
<option >
DR10
</option>
<option >
DR10Collab
</option>
<option >
DR9
</option>
<option >
TestDR10
</option>
<option >
DR8
</option>
<option >
DR7
</option>
<option >
SEGUE2
</option>
<option >
GalexGR6
</option>
<option >
Match2
</option>
<option >
MatchDB
</option>
<option >
DR4
</option>
<option >
DR3
</option>
<option >
DR2
</option>
<option >
DR1
</option>
<option >
GalexGR5
</option>
<option >
DR6
</option>
<option >
sensor4
</option>
<option >
sensor
</option>
<option >
2MASS
</option>
<option >
GalexGR2
</option>
<option >
GalexGR3
</option>
<option >
FIRST
</option>
<option >
DR5
</option>
<option >
ROSAT
</option>
<option >
TestDR9
</option>
<option >
2DF
</option>
</select>
</td>
<td align="center" style="width: 100px">
<input type="text" style="width: 100%" id="table" name="table" value="MyTable_0" />
</td>
<td align="center">
<input type="text" name="taskname" style="width: 100%" value="My Query" />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table id="querypane" cellspacing="1" cellpadding="0" class="bar" style="padding: 0 0 0 0;
width: 100%;">
<tr>
<td style="text-align: center;">
<input id="sampCheck" type="button" value="Samples" onclick="toggleSamples();" />
</td>
<td style="text-align: center;">
<input id="histCheck" type="button" value="Recent" onclick="toggleHist();" />
</td>
<td style="text-align: center;">
<input id="clearButton" type="button" onclick="clearQry();" value="Clear" />
</td>
<td>
</td>
<td style="padding: 0 5 0 5; width: 25;">
<div style="white-space: nowrap" id="timer">
</div>
</td>
<td width="100%">
<div class="message" style="text-align: right; padding-right: 5; height: 15px; overflow: hidden;"
onmouseover="cjshowqsM();" onmouseout="cjhideqsM();" id="message">
</div>
<div style="visibility: hidden; z-index: 100; position: absolute;" id="mmessage">
</div>
</td>
<td style="text-align: center;">
<input type="hidden" id="syntax" name="syntax" value="false" />
<input id="syntaxButton" title="Check query syntax. (CTRL-S)" type="button" value="Syntax"
onclick="checksyntax()" />
</td>
<td style="text-align: center;">
<input id="planButton" title="Show estimated query plan. (CTRL-P)" type="button" value="Plan"
onclick="getplan();" />
</td>
<td style="text-align: center;">
<input id="quickButton" title="Runs the query instantaneously. Short duration and data limit. (CTRL-Q)"
value="Quick" type="button" onclick="submitQuickQuery();" />
</td>
<td style="text-align: center">
<input id="submitButton" value="Submit" title="Submits your query. Longest duration. (CTRL-U)"
type="button" onclick="submitQuery();" />
</td>
</tr>
</table>
</td>
</tr>
<tr id="queryRow">
<td id="queryCell" height="100%" style="padding: 0 1 1 0;">
</td>
</tr>
<tr id="resultsRow" style="display: none;">
<td id="resultsCell" width="100%" height="65%">
<iframe name="resultPane" id="resultPane" height="100%" style="height: 100%; width: 100%"
src="output/vodataclean.aspx" frameborder="0" onload="trmenu();" scrolling="auto">
</iframe>
</td>
</tr>
<tr id="menuRow">
<td>
<table class="bar" id="windowMenu" cellpadding="0" cellspacing="1" border="0" style="width: 100%;">
<tr>
<td style="font-variant: small-caps; padding: 0 10 0 10">
Results
</td>
<td>
<input type="button" value="Plot" onclick="window.open('output/voplot/loadjvt.aspx','plot','');" />
</td>
<td>
<input type="button" value="Save As" onclick="save();" />
</td>
<td>
<select id="ddl">
<option>HTML</option>
<option>CSV</option>
<option>VOTable</option>
<option>DataSet</option>
</select>
</td>
<td width="100%">
&nbsp;
</td>
<td style="padding-right: 5;">
</td>
<td style="font-variant: small-caps; padding: 0 10 0 10">
Display
</td>
<td>
<input type="button" title="CTRL-J" value="Query" onclick="maxQuery();" />
</td>
<td>
<input type="button" title="CTRL-K" value="Results" onclick="maxResults();" />
</td>
<td>
<input type="button" title="CTRL-H" value="Both" onclick="setEditorMid();" />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td style="">
<p class="footer" style="padding:2 2 2 2;margin:0 0 0 0;">
<a href="http://skyserver.sdss3.org/contact/default.asp?subject=CasJobs+Issue:+&smtp=mail.pha.jhu.edu&helpdesk=helpdesk@sdss3.org&url=http%3a%2f%2fskyservice.pha.jhu.edu%2fcasjobs%2fSubmitJob.aspx&username=Dustin+Lang&userid=dstn &email=dstn@astro.princeton.edu">Contact</a>
<br/>
v3_8_4
</p>
</td>
</tr>
</table>
</form>
<form name="svqry" id="Form1" action="output/svqry.aspx" method="post" target="hidden"
style="display: none;">
<input type="hidden" name="USQL" id="USQL" value="" />
<input type="hidden" name="UCONTEXT" id="UCONTEXT" value="" />
</form>
<iframe name="hidden" style="display: none"></iframe>
<input type="hidden" id="wsid" value="2092080249" />
<div id="samples" style="position: absolute; display: none; width: 200; vertical-align: text-top;
overflow: auto; z-index: 100; padding: 2 2 2 2;" class="transparent" >
</div>
<div id="all_samples" style="display:none;">
<div id="global_samples">
<div><a href="#" onclick="setQuery('q_377384944');" onmouseover="showSample('q_377384944',this);" onmouseout="cjhideqs();">Basic SELECT FROM WHERE</a></div>
<div><a href="#" onclick="setQuery('q_1917342500');" onmouseover="showSample('q_1917342500',this);" onmouseout="cjhideqs();">Galaxies two criteria</a></div>
<div><a href="#" onclick="setQuery('q_199934847');" onmouseover="showSample('q_199934847',this);" onmouseout="cjhideqs();">QSOs in spectroscopy</a></div>
<div><a href="#" onclick="setQuery('q_1794636122');" onmouseover="showSample('q_1794636122',this);" onmouseout="cjhideqs();">Using BETWEEN</a></div>
<div><a href="#" onclick="setQuery('q_2053263464');" onmouseover="showSample('q_2053263464',this);" onmouseout="cjhideqs();">Spatial unit vectors</a></div>
<div><a href="#" onclick="setQuery('q_610026851');" onmouseover="showSample('q_610026851',this);" onmouseout="cjhideqs();">CVs using colors</a></div>
<div><a href="#" onclick="setQuery('q_347053935');" onmouseover="showSample('q_347053935',this);" onmouseout="cjhideqs();">Data subsample</a></div>
<div><a href="#" onclick="setQuery('q_1503241840');" onmouseover="showSample('q_1503241840',this);" onmouseout="cjhideqs();">Low z QSOs by colors</a></div>
<div><a href="#" onclick="setQuery('q_1093157909');" onmouseover="showSample('q_1093157909',this);" onmouseout="cjhideqs();">Velocities and errors</a></div>
<div><a href="#" onclick="setQuery('q_1182730545');" onmouseover="showSample('q_1182730545',this);" onmouseout="cjhideqs();">Galaxies By Emission Lines</a></div>
<div><a href="#" onclick="setQuery('q_1884957360');" onmouseover="showSample('q_1884957360',this);" onmouseout="cjhideqs();">Moving asteroids</a></div>
<div><a href="#" onclick="setQuery('q_1314337809');" onmouseover="showSample('q_1314337809',this);" onmouseout="cjhideqs();">Quasars in imaging</a></div>
<div><a href="#" onclick="setQuery('q_453086348');" onmouseover="showSample('q_453086348',this);" onmouseout="cjhideqs();">Object counts and logic</a></div>
<div><a href="#" onclick="setQuery('q_704206862');" onmouseover="showSample('q_704206862',this);" onmouseout="cjhideqs();">Galaxy star blends</a></div>
<div><a href="#" onclick="setQuery('q_689961383');" onmouseover="showSample('q_689961383',this);" onmouseout="cjhideqs();">Stars in specific fields</a></div>
<div><a href="#" onclick="setQuery('q_410365955');" onmouseover="showSample('q_410365955',this);" onmouseout="cjhideqs();">Using three tables</a></div>
<div><a href="#" onclick="setQuery('q_1684523170');" onmouseover="showSample('q_1684523170',this);" onmouseout="cjhideqs();">Objects close pairs</a></div>
<div><a href="#" onclick="setQuery('q_1823934513');" onmouseover="showSample('q_1823934513',this);" onmouseout="cjhideqs();">Stars multiply measured</a></div>
<div><a href="#" onclick="setQuery('q_348348979');" onmouseover="showSample('q_348348979',this);" onmouseout="cjhideqs();">Errors using flags</a></div>
<div><a href="#" onclick="setQuery('q_569145814');" onmouseover="showSample('q_569145814',this);" onmouseout="cjhideqs();">Elliptical galaxies</a></div>
<div><a href="#" onclick="setQuery('q_1687216546');" onmouseover="showSample('q_1687216546',this);" onmouseout="cjhideqs();">Galaxies blue centers</a></div>
<div><a href="#" onclick="setQuery('q_113893222');" onmouseover="showSample('q_113893222',this);" onmouseout="cjhideqs();">Diameter limited galaxies</a></div>
<div><a href="#" onclick="setQuery('q_1471444940');" onmouseover="showSample('q_1471444940',this);" onmouseout="cjhideqs();">Extremely red galaxies</a></div>
<div><a href="#" onclick="setQuery('q_1092529461');" onmouseover="showSample('q_1092529461',this);" onmouseout="cjhideqs();">LRG sample</a></div>
<div><a href="#" onclick="setQuery('q_1476423508');" onmouseover="showSample('q_1476423508',this);" onmouseout="cjhideqs();">Spectra of Red Stars</a></div>
<div><a href="#" onclick="setQuery('q_1964088379');" onmouseover="showSample('q_1964088379',this);" onmouseout="cjhideqs();">Galaxy counts HTM grid</a></div>
<div><a href="#" onclick="setQuery('q_1609807292');" onmouseover="showSample('q_1609807292',this);" onmouseout="cjhideqs();">Binary stars colors</a></div>
<div><a href="#" onclick="setQuery('q_949416951');" onmouseover="showSample('q_949416951',this);" onmouseout="cjhideqs();">Galaxies unsaturated near coord</a></div>
<div><a href="#" onclick="setQuery('q_1820036051');" onmouseover="showSample('q_1820036051',this);" onmouseout="cjhideqs();">Search near BCGs</a></div>
<div><a href="#" onclick="setQuery('q_2086102066');" onmouseover="showSample('q_2086102066',this);" onmouseout="cjhideqs();">Multiple Detections and Time Series</a></div>
</div>
<div id="batchadmin_samples">
<div><a href="#" onclick="setQuery('q_1342567403');" onmouseover="showSample('q_1342567403',this);" onmouseout="cjhideqs();">Queries longer than 10min</a></div>
<div><a href="#" onclick="setQuery('q_1185292591');" onmouseover="showSample('q_1185292591',this);" onmouseout="cjhideqs();">Accounts created monthly</a></div>
</div>
<div id="dr1_samples">
<div><a href="#" onclick="setQuery('q_2127032053');" onmouseover="showSample('q_2127032053',this);" onmouseout="cjhideqs();">Basic SELECT FROM WHERE</a></div>
<div><a href="#" onclick="setQuery('q_1822251911');" onmouseover="showSample('q_1822251911',this);" onmouseout="cjhideqs();">Galaxies two criteria</a></div>
<div><a href="#" onclick="setQuery('q_2112964880');" onmouseover="showSample('q_2112964880',this);" onmouseout="cjhideqs();">Unclassified spectra</a></div>
<div><a href="#" onclick="setQuery('q_1876103269');" onmouseover="showSample('q_1876103269',this);" onmouseout="cjhideqs();">Galaxies multiple criteria</a></div>
<div><a href="#" onclick="setQuery('q_1604660031');" onmouseover="showSample('q_1604660031',this);" onmouseout="cjhideqs();">Spatial unit vectors</a></div>
<div><a href="#" onclick="setQuery('q_1209894154');" onmouseover="showSample('q_1209894154',this);" onmouseout="cjhideqs();">CVs using colors</a></div>
<div><a href="#" onclick="setQuery('q_1732295176');" onmouseover="showSample('q_1732295176',this);" onmouseout="cjhideqs();">Data subsample</a></div>
<div><a href="#" onclick="setQuery('q_2122410695');" onmouseover="showSample('q_2122410695',this);" onmouseout="cjhideqs();">Low z QSOs by colors</a></div>
<div><a href="#" onclick="setQuery('q_162421342');" onmouseover="showSample('q_162421342',this);" onmouseout="cjhideqs();">Velocities and errors</a></div>
<div><a href="#" onclick="setQuery('q_1947188265');" onmouseover="showSample('q_1947188265',this);" onmouseout="cjhideqs();">Using BETWEEN</a></div>
<div><a href="#" onclick="setQuery('q_1076082999');" onmouseover="showSample('q_1076082999',this);" onmouseout="cjhideqs();">Moving asteroids</a></div>
<div><a href="#" onclick="setQuery('q_362452986');" onmouseover="showSample('q_362452986',this);" onmouseout="cjhideqs();">Quasars in imaging</a></div>
<div><a href="#" onclick="setQuery('q_2140829941');" onmouseover="showSample('q_2140829941',this);" onmouseout="cjhideqs();">Object counts and logic</a></div>
<div><a href="#" onclick="setQuery('q_1307734809');" onmouseover="showSample('q_1307734809',this);" onmouseout="cjhideqs();">Galaxy star blends</a></div>
<div><a href="#" onclick="setQuery('q_699861840');" onmouseover="showSample('q_699861840',this);" onmouseout="cjhideqs();">Stars in specific fields</a></div>
<div><a href="#" onclick="setQuery('q_1448724282');" onmouseover="showSample('q_1448724282',this);" onmouseout="cjhideqs();">Using three tables</a></div>
<div><a href="#" onclick="setQuery('q_1373505727');" onmouseover="showSample('q_1373505727',this);" onmouseout="cjhideqs();">Objects close pairs</a></div>
<div><a href="#" onclick="setQuery('q_203899950');" onmouseover="showSample('q_203899950',this);" onmouseout="cjhideqs();">QSOs in spectroscopy</a></div>
<div><a href="#" onclick="setQuery('q_160825834');" onmouseover="showSample('q_160825834',this);" onmouseout="cjhideqs();">Errors using flags</a></div>
<div><a href="#" onclick="setQuery('q_1984607857');" onmouseover="showSample('q_1984607857',this);" onmouseout="cjhideqs();">Elliptical galaxies</a></div>
<div><a href="#" onclick="setQuery('q_2071057527');" onmouseover="showSample('q_2071057527',this);" onmouseout="cjhideqs();">Galaxies blue centers</a></div>
<div><a href="#" onclick="setQuery('q_1616963259');" onmouseover="showSample('q_1616963259',this);" onmouseout="cjhideqs();">Diameter limited galaxies</a></div>
<div><a href="#" onclick="setQuery('q_1224142175');" onmouseover="showSample('q_1224142175',this);" onmouseout="cjhideqs();">Extremely red galaxies</a></div>
<div><a href="#" onclick="setQuery('q_733458258');" onmouseover="showSample('q_733458258',this);" onmouseout="cjhideqs();">LRG sample</a></div>
<div><a href="#" onclick="setQuery('q_1195635002');" onmouseover="showSample('q_1195635002',this);" onmouseout="cjhideqs();">Galaxies by spectra</a></div>
<div><a href="#" onclick="setQuery('q_792880405');" onmouseover="showSample('q_792880405',this);" onmouseout="cjhideqs();">Galaxies by spectra2</a></div>
<div><a href="#" onclick="setQuery('q_1564994359');" onmouseover="showSample('q_1564994359',this);" onmouseout="cjhideqs();">Binary stars colors</a></div>
<div><a href="#" onclick="setQuery('q_491051768');" onmouseover="showSample('q_491051768',this);" onmouseout="cjhideqs();">QSOs broadlines near galaxy</a></div>
<div><a href="#" onclick="setQuery('q_453518089');" onmouseover="showSample('q_453518089',this);" onmouseout="cjhideqs();">Galaxies unsaturated near coord</a></div>
<div><a href="#" onclick="setQuery('q_1011044940');" onmouseover="showSample('q_1011044940',this);" onmouseout="cjhideqs();">Ellipticals odd lines</a></div>
<div><a href="#" onclick="setQuery('q_1835462071');" onmouseover="showSample('q_1835462071',this);" onmouseout="cjhideqs();">Search near BCGs</a></div>
<div><a href="#" onclick="setQuery('q_715981218');" onmouseover="showSample('q_715981218',this);" onmouseout="cjhideqs();">Broadest spectral lines</a></div>
<div><a href="#" onclick="setQuery('q_1104283183');" onmouseover="showSample('q_1104283183',this);" onmouseout="cjhideqs();">Gridded galaxy counts</a></div>
<div><a href="#" onclick="setQuery('q_1837021711');" onmouseover="showSample('q_1837021711',this);" onmouseout="cjhideqs();">Galaxy counts HTM grid</a></div>
<div><a href="#" onclick="setQuery('q_2135502459');" onmouseover="showSample('q_2135502459',this);" onmouseout="cjhideqs();">Stars multiply measured</a></div>
<div><a href="#" onclick="setQuery('q_114193719');" onmouseover="showSample('q_114193719',this);" onmouseout="cjhideqs();">Checking SDSS footprint</a></div>
</div>
<div id="dr10_samples">
<div><a href="#" onclick="setQuery('q_318573181');" onmouseover="showSample('q_318573181',this);" onmouseout="cjhideqs();">Basic SELECT FROM WHERE</a></div>
<div><a href="#" onclick="setQuery('q_2121526033');" onmouseover="showSample('q_2121526033',this);" onmouseout="cjhideqs();">Galaxies two criteria</a></div>
<div><a href="#" onclick="setQuery('q_1702999202');" onmouseover="showSample('q_1702999202',this);" onmouseout="cjhideqs();">QSOs in spectroscopy</a></div>
<div><a href="#" onclick="setQuery('q_807954861');" onmouseover="showSample('q_807954861',this);" onmouseout="cjhideqs();">Using BETWEEN</a></div>
<div><a href="#" onclick="setQuery('q_1601839065');" onmouseover="showSample('q_1601839065',this);" onmouseout="cjhideqs();">Spatial unit vectors</a></div>
<div><a href="#" onclick="setQuery('q_1407015576');" onmouseover="showSample('q_1407015576',this);" onmouseout="cjhideqs();">CVs using colors</a></div>
<div><a href="#" onclick="setQuery('q_810186038');" onmouseover="showSample('q_810186038',this);" onmouseout="cjhideqs();">Data subsample</a></div>
<div><a href="#" onclick="setQuery('q_446289279');" onmouseover="showSample('q_446289279',this);" onmouseout="cjhideqs();">Low z QSOs by colors</a></div>
<div><a href="#" onclick="setQuery('q_832506840');" onmouseover="showSample('q_832506840',this);" onmouseout="cjhideqs();">Velocities and errors</a></div>
<div><a href="#" onclick="setQuery('q_1549577480');" onmouseover="showSample('q_1549577480',this);" onmouseout="cjhideqs();">Galaxies By Emission Lines</a></div>
<div><a href="#" onclick="setQuery('q_1075597663');" onmouseover="showSample('q_1075597663',this);" onmouseout="cjhideqs();">Moving asteroids</a></div>
<div><a href="#" onclick="setQuery('q_387047336');" onmouseover="showSample('q_387047336',this);" onmouseout="cjhideqs();">Quasars in imaging</a></div>
<div><a href="#" onclick="setQuery('q_464249349');" onmouseover="showSample('q_464249349',this);" onmouseout="cjhideqs();">Object counts and logic</a></div>
<div><a href="#" onclick="setQuery('q_1257775135');" onmouseover="showSample('q_1257775135',this);" onmouseout="cjhideqs();">Galaxy star blends</a></div>
<div><a href="#" onclick="setQuery('q_1773962834');" onmouseover="showSample('q_1773962834',this);" onmouseout="cjhideqs();">Stars in specific fields</a></div>
<div><a href="#" onclick="setQuery('q_1890051708');" onmouseover="showSample('q_1890051708',this);" onmouseout="cjhideqs();">Using three tables</a></div>
<div><a href="#" onclick="setQuery('q_2042342521');" onmouseover="showSample('q_2042342521',this);" onmouseout="cjhideqs();">Objects close pairs</a></div>
<div><a href="#" onclick="setQuery('q_1271476914');" onmouseover="showSample('q_1271476914',this);" onmouseout="cjhideqs();">Stars multiply measured</a></div>
<div><a href="#" onclick="setQuery('q_162268584');" onmouseover="showSample('q_162268584',this);" onmouseout="cjhideqs();">Errors using flags</a></div>
<div><a href="#" onclick="setQuery('q_200158383');" onmouseover="showSample('q_200158383',this);" onmouseout="cjhideqs();">Elliptical galaxies</a></div>
<div><a href="#" onclick="setQuery('q_220572073');" onmouseover="showSample('q_220572073',this);" onmouseout="cjhideqs();">Galaxies blue centers</a></div>
<div><a href="#" onclick="setQuery('q_454660149');" onmouseover="showSample('q_454660149',this);" onmouseout="cjhideqs();">Diameter limited galaxies</a></div>
<div><a href="#" onclick="setQuery('q_1221376687');" onmouseover="showSample('q_1221376687',this);" onmouseout="cjhideqs();">Extremely red galaxies</a></div>
<div><a href="#" onclick="setQuery('q_663779516');" onmouseover="showSample('q_663779516',this);" onmouseout="cjhideqs();">LRG sample</a></div>
<div><a href="#" onclick="setQuery('q_338186821');" onmouseover="showSample('q_338186821',this);" onmouseout="cjhideqs();">Spectra of Red Stars</a></div>
<div><a href="#" onclick="setQuery('q_284125386');" onmouseover="showSample('q_284125386',this);" onmouseout="cjhideqs();">Galaxy counts HTM grid</a></div>
<div><a href="#" onclick="setQuery('q_1363234497');" onmouseover="showSample('q_1363234497',this);" onmouseout="cjhideqs();">Binary stars colors</a></div>
<div><a href="#" onclick="setQuery('q_911927524');" onmouseover="showSample('q_911927524',this);" onmouseout="cjhideqs();">Galaxies unsaturated near coord</a></div>
<div><a href="#" onclick="setQuery('q_2046113808');" onmouseover="showSample('q_2046113808',this);" onmouseout="cjhideqs();">Search near BCGs</a></div>
<div><a href="#" onclick="setQuery('q_1348920221');" onmouseover="showSample('q_1348920221',this);" onmouseout="cjhideqs();">Multiple Detections and Time Series</a></div>
<div><a href="#" onclick="setQuery('q_619277145');" onmouseover="showSample('q_619277145',this);" onmouseout="cjhideqs();">All APOGEE Plate Visits</a></div>
<div><a href="#" onclick="setQuery('q_1575944052');" onmouseover="showSample('q_1575944052',this);" onmouseout="cjhideqs();">ASPCAP Parameters and Errors</a></div>
<div><a href="#" onclick="setQuery('q_873427785');" onmouseover="showSample('q_873427785',this);" onmouseout="cjhideqs();">APOGEE Stars No BAD Flags</a></div>
<div><a href="#" onclick="setQuery('q_509946294');" onmouseover="showSample('q_509946294',this);" onmouseout="cjhideqs();">ASPCAP Params for Cluster Mbrs</a></div>
<div><a href="#" onclick="setQuery('q_1886714918');" onmouseover="showSample('q_1886714918',this);" onmouseout="cjhideqs();">APOGEE Proper Motions</a></div>
<div><a href="#" onclick="setQuery('q_214541362');" onmouseover="showSample('q_214541362',this);" onmouseout="cjhideqs();">APOGEE Stars Near Cluster Ctr</a></div>
<div><a href="#" onclick="setQuery('q_114253696');" onmouseover="showSample('q_114253696',this);" onmouseout="cjhideqs();">RVs for Individual APOGEE Visits</a></div>
<div><a href="#" onclick="setQuery('q_286757891');" onmouseover="showSample('q_286757891',this);" onmouseout="cjhideqs();">APOGEE and SEGUE Spectra</a></div>
<div><a href="#" onclick="setQuery('q_251526975');" onmouseover="showSample('q_251526975',this);" onmouseout="cjhideqs();">SDSS Photometry for APOGEE Stars</a></div>
</div>
<div id="dr10collab_samples">
<div><a href="#" onclick="setQuery('q_341160974');" onmouseover="showSample('q_341160974',this);" onmouseout="cjhideqs();">Basic SELECT FROM WHERE</a></div>
<div><a href="#" onclick="setQuery('q_2088747594');" onmouseover="showSample('q_2088747594',this);" onmouseout="cjhideqs();">Galaxies two criteria</a></div>
<div><a href="#" onclick="setQuery('q_326961301');" onmouseover="showSample('q_326961301',this);" onmouseout="cjhideqs();">QSOs in spectroscopy</a></div>
<div><a href="#" onclick="setQuery('q_1559254220');" onmouseover="showSample('q_1559254220',this);" onmouseout="cjhideqs();">Using BETWEEN</a></div>
<div><a href="#" onclick="setQuery('q_364596238');" onmouseover="showSample('q_364596238',this);" onmouseout="cjhideqs();">Spatial unit vectors</a></div>
<div><a href="#" onclick="setQuery('q_1145250273');" onmouseover="showSample('q_1145250273',this);" onmouseout="cjhideqs();">CVs using colors</a></div>
<div><a href="#" onclick="setQuery('q_965086605');" onmouseover="showSample('q_965086605',this);" onmouseout="cjhideqs();">Data subsample</a></div>
<div><a href="#" onclick="setQuery('q_893526326');" onmouseover="showSample('q_893526326',this);" onmouseout="cjhideqs();">Low z QSOs by colors</a></div>
<div><a href="#" onclick="setQuery('q_1359629897');" onmouseover="showSample('q_1359629897',this);" onmouseout="cjhideqs();">Velocities and errors</a></div>
<div><a href="#" onclick="setQuery('q_2046520797');" onmouseover="showSample('q_2046520797',this);" onmouseout="cjhideqs();">Galaxies By Emission Lines</a></div>
<div><a href="#" onclick="setQuery('q_1722069906');" onmouseover="showSample('q_1722069906',this);" onmouseout="cjhideqs();">Moving asteroids</a></div>
<div><a href="#" onclick="setQuery('q_504267227');" onmouseover="showSample('q_504267227',this);" onmouseout="cjhideqs();">Quasars in imaging</a></div>
<div><a href="#" onclick="setQuery('q_273521898');" onmouseover="showSample('q_273521898',this);" onmouseout="cjhideqs();">Object counts and logic</a></div>
<div><a href="#" onclick="setQuery('q_1145880200');" onmouseover="showSample('q_1145880200',this);" onmouseout="cjhideqs();">Galaxy star blends</a></div>
<div><a href="#" onclick="setQuery('q_1019525219');" onmouseover="showSample('q_1019525219',this);" onmouseout="cjhideqs();">Stars in specific fields</a></div>
<div><a href="#" onclick="setQuery('q_891488825');" onmouseover="showSample('q_891488825',this);" onmouseout="cjhideqs();">Using three tables</a></div>
<div><a href="#" onclick="setQuery('q_1456890876');" onmouseover="showSample('q_1456890876',this);" onmouseout="cjhideqs();">Objects close pairs</a></div>
<div><a href="#" onclick="setQuery('q_1683900573');" onmouseover="showSample('q_1683900573',this);" onmouseout="cjhideqs();">Stars multiply measured</a></div>
<div><a href="#" onclick="setQuery('q_538248463');" onmouseover="showSample('q_538248463',this);" onmouseout="cjhideqs();">Errors using flags</a></div>
<div><a href="#" onclick="setQuery('q_2107503000');" onmouseover="showSample('q_2107503000',this);" onmouseout="cjhideqs();">Elliptical galaxies</a></div>
<div><a href="#" onclick="setQuery('q_1724772452');" onmouseover="showSample('q_1724772452',this);" onmouseout="cjhideqs();">Galaxies blue centers</a></div>
<div><a href="#" onclick="setQuery('q_34323696');" onmouseover="showSample('q_34323696',this);" onmouseout="cjhideqs();">Diameter limited galaxies</a></div>
<div><a href="#" onclick="setQuery('q_357369514');" onmouseover="showSample('q_357369514',this);" onmouseout="cjhideqs();">Extremely red galaxies</a></div>
<div><a href="#" onclick="setQuery('q_2085753961');" onmouseover="showSample('q_2085753961',this);" onmouseout="cjhideqs();">LRG sample</a></div>
<div><a href="#" onclick="setQuery('q_1598688566');" onmouseover="showSample('q_1598688566',this);" onmouseout="cjhideqs();">Spectra of Red Stars</a></div>
<div><a href="#" onclick="setQuery('q_1031426103');" onmouseover="showSample('q_1031426103',this);" onmouseout="cjhideqs();">Galaxy counts HTM grid</a></div>
<div><a href="#" onclick="setQuery('q_907308906');" onmouseover="showSample('q_907308906',this);" onmouseout="cjhideqs();">Binary stars colors</a></div>
<div><a href="#" onclick="setQuery('q_1246974053');" onmouseover="showSample('q_1246974053',this);" onmouseout="cjhideqs();">Galaxies unsaturated near coord</a></div>
<div><a href="#" onclick="setQuery('q_1446002135');" onmouseover="showSample('q_1446002135',this);" onmouseout="cjhideqs();">Search near BCGs</a></div>
<div><a href="#" onclick="setQuery('q_45055564');" onmouseover="showSample('q_45055564',this);" onmouseout="cjhideqs();">Multiple Detections and Time Series</a></div>
<div><a href="#" onclick="setQuery('q_1674347198');" onmouseover="showSample('q_1674347198',this);" onmouseout="cjhideqs();">All APOGEE Plate Visits</a></div>
<div><a href="#" onclick="setQuery('q_29000041');" onmouseover="showSample('q_29000041',this);" onmouseout="cjhideqs();">ASPCAP Parameters and Errors</a></div>
<div><a href="#" onclick="setQuery('q_1193882752');" onmouseover="showSample('q_1193882752',this);" onmouseout="cjhideqs();">APOGEE Stars No BAD Flags</a></div>
<div><a href="#" onclick="setQuery('q_1745805745');" onmouseover="showSample('q_1745805745',this);" onmouseout="cjhideqs();">ASPCAP Params for Cluster Mbrs</a></div>
<div><a href="#" onclick="setQuery('q_111582421');" onmouseover="showSample('q_111582421',this);" onmouseout="cjhideqs();">APOGEE Proper Motions</a></div>
<div><a href="#" onclick="setQuery('q_1441850959');" onmouseover="showSample('q_1441850959',this);" onmouseout="cjhideqs();">APOGEE Stars Near Cluster Ctr</a></div>
<div><a href="#" onclick="setQuery('q_988146083');" onmouseover="showSample('q_988146083',this);" onmouseout="cjhideqs();">RVs for Individual APOGEE Visits</a></div>
<div><a href="#" onclick="setQuery('q_197092168');" onmouseover="showSample('q_197092168',this);" onmouseout="cjhideqs();">APOGEE and SEGUE Spectra</a></div>
<div><a href="#" onclick="setQuery('q_871745526');" onmouseover="showSample('q_871745526',this);" onmouseout="cjhideqs();">SDSS Photometry for APOGEE Stars</a></div>
</div>
<div id="dr2_samples">
<div><a href="#" onclick="setQuery('q_658663612');" onmouseover="showSample('q_658663612',this);" onmouseout="cjhideqs();">Basic SELECT FROM WHERE</a></div>
<div><a href="#" onclick="setQuery('q_2046242728');" onmouseover="showSample('q_2046242728',this);" onmouseout="cjhideqs();">Galaxies two criteria</a></div>
<div><a href="#" onclick="setQuery('q_100466571');" onmouseover="showSample('q_100466571',this);" onmouseout="cjhideqs();">Unclassified spectra</a></div>
<div><a href="#" onclick="setQuery('q_473336052');" onmouseover="showSample('q_473336052',this);" onmouseout="cjhideqs();">Galaxies multiple criteria</a></div>
<div><a href="#" onclick="setQuery('q_1038272356');" onmouseover="showSample('q_1038272356',this);" onmouseout="cjhideqs();">Spatial unit vectors</a></div>
<div><a href="#" onclick="setQuery('q_1673976505');" onmouseover="showSample('q_1673976505',this);" onmouseout="cjhideqs();">CVs using colors</a></div>
<div><a href="#" onclick="setQuery('q_1262886835');" onmouseover="showSample('q_1262886835',this);" onmouseout="cjhideqs();">Data subsample</a></div>
<div><a href="#" onclick="setQuery('q_1206688596');" onmouseover="showSample('q_1206688596',this);" onmouseout="cjhideqs();">Low z QSOs by colors</a></div>
<div><a href="#" onclick="setQuery('q_1341462147');" onmouseover="showSample('q_1341462147',this);" onmouseout="cjhideqs();">Velocities and errors</a></div>
<div><a href="#" onclick="setQuery('q_1497461636');" onmouseover="showSample('q_1497461636',this);" onmouseout="cjhideqs();">Using BETWEEN</a></div>
<div><a href="#" onclick="setQuery('q_166620452');" onmouseover="showSample('q_166620452',this);" onmouseout="cjhideqs();">Moving asteroids</a></div>
<div><a href="#" onclick="setQuery('q_605771979');" onmouseover="showSample('q_605771979',this);" onmouseout="cjhideqs();">Quasars in imaging</a></div>
<div><a href="#" onclick="setQuery('q_384152764');" onmouseover="showSample('q_384152764',this);" onmouseout="cjhideqs();">Object counts and logic</a></div>
<div><a href="#" onclick="setQuery('q_239583990');" onmouseover="showSample('q_239583990',this);" onmouseout="cjhideqs();">Galaxy star blends</a></div>
<div><a href="#" onclick="setQuery('q_513883755');" onmouseover="showSample('q_513883755',this);" onmouseout="cjhideqs();">Stars in specific fields</a></div>
<div><a href="#" onclick="setQuery('q_123633451');" onmouseover="showSample('q_123633451',this);" onmouseout="cjhideqs();">Using three tables</a></div>
<div><a href="#" onclick="setQuery('q_964285562');" onmouseover="showSample('q_964285562',this);" onmouseout="cjhideqs();">Objects close pairs</a></div>
<div><a href="#" onclick="setQuery('q_1428429823');" onmouseover="showSample('q_1428429823',this);" onmouseout="cjhideqs();">QSOs in spectroscopy</a></div>
<div><a href="#" onclick="setQuery('q_1014719417');" onmouseover="showSample('q_1014719417',this);" onmouseout="cjhideqs();">Errors using flags</a></div>
<div><a href="#" onclick="setQuery('q_955083894');" onmouseover="showSample('q_955083894',this);" onmouseout="cjhideqs();">Elliptical galaxies</a></div>
<div><a href="#" onclick="setQuery('q_2067166502');" onmouseover="showSample('q_2067166502',this);" onmouseout="cjhideqs();">Galaxies blue centers</a></div>
<div><a href="#" onclick="setQuery('q_1081925782');" onmouseover="showSample('q_1081925782',this);" onmouseout="cjhideqs();">Diameter limited galaxies</a></div>
<div><a href="#" onclick="setQuery('q_1379940380');" onmouseover="showSample('q_1379940380',this);" onmouseout="cjhideqs();">Extremely red galaxies</a></div>
<div><a href="#" onclick="setQuery('q_5571651');" onmouseover="showSample('q_5571651',this);" onmouseout="cjhideqs();">LRG sample</a></div>
<div><a href="#" onclick="setQuery('q_284612279');" onmouseover="showSample('q_284612279',this);" onmouseout="cjhideqs();">Galaxies by spectra</a></div>
<div><a href="#" onclick="setQuery('q_1514959216');" onmouseover="showSample('q_1514959216',this);" onmouseout="cjhideqs();">Galaxies by spectra2</a></div>
<div><a href="#" onclick="setQuery('q_1269992360');" onmouseover="showSample('q_1269992360',this);" onmouseout="cjhideqs();">Binary stars colors</a></div>
<div><a href="#" onclick="setQuery('q_1619536327');" onmouseover="showSample('q_1619536327',this);" onmouseout="cjhideqs();">QSOs broadlines near galaxy</a></div>
<div><a href="#" onclick="setQuery('q_234499396');" onmouseover="showSample('q_234499396',this);" onmouseout="cjhideqs();">Galaxies unsaturated near coord</a></div>
<div><a href="#" onclick="setQuery('q_386537157');" onmouseover="showSample('q_386537157',this);" onmouseout="cjhideqs();">Ellipticals odd lines</a></div>
<div><a href="#" onclick="setQuery('q_506396296');" onmouseover="showSample('q_506396296',this);" onmouseout="cjhideqs();">Search near BCGs</a></div>
<div><a href="#" onclick="setQuery('q_1230693149');" onmouseover="showSample('q_1230693149',this);" onmouseout="cjhideqs();">Broadest spectral lines</a></div>
<div><a href="#" onclick="setQuery('q_2026053022');" onmouseover="showSample('q_2026053022',this);" onmouseout="cjhideqs();">Gridded galaxy counts</a></div>
<div><a href="#" onclick="setQuery('q_643163052');" onmouseover="showSample('q_643163052',this);" onmouseout="cjhideqs();">Galaxy counts HTM grid</a></div>
<div><a href="#" onclick="setQuery('q_1483607040');" onmouseover="showSample('q_1483607040',this);" onmouseout="cjhideqs();">Stars multiply measured</a></div>
<div><a href="#" onclick="setQuery('q_1458312124');" onmouseover="showSample('q_1458312124',this);" onmouseout="cjhideqs();">Checking SDSS footprint</a></div>
</div>
<div id="dr3_samples">
<div><a href="#" onclick="setQuery('q_998698239');" onmouseover="showSample('q_998698239',this);" onmouseout="cjhideqs();">Basic SELECT FROM WHERE</a></div>
<div><a href="#" onclick="setQuery('q_324753475');" onmouseover="showSample('q_324753475',this);" onmouseout="cjhideqs();">Galaxies two criteria</a></div>
<div><a href="#" onclick="setQuery('q_638887334');" onmouseover="showSample('q_638887334',this);" onmouseout="cjhideqs();">Unclassified spectra</a></div>
<div><a href="#" onclick="setQuery('q_1942123503');" onmouseover="showSample('q_1942123503',this);" onmouseout="cjhideqs();">Galaxies multiple criteria</a></div>
<div><a href="#" onclick="setQuery('q_1122950537');" onmouseover="showSample('q_1122950537',this);" onmouseout="cjhideqs();">Spatial unit vectors</a></div>
<div><a href="#" onclick="setQuery('q_203970260');" onmouseover="showSample('q_203970260',this);" onmouseout="cjhideqs();">CVs using colors</a></div>
<div><a href="#" onclick="setQuery('q_155362706');" onmouseover="showSample('q_155362706',this);" onmouseout="cjhideqs();">Data subsample</a></div>
<div><a href="#" onclick="setQuery('q_2008048623');" onmouseover="showSample('q_2008048623',this);" onmouseout="cjhideqs();">Low z QSOs by colors</a></div>
<div><a href="#" onclick="setQuery('q_468185944');" onmouseover="showSample('q_468185944',this);" onmouseout="cjhideqs();">Velocities and errors</a></div>
<div><a href="#" onclick="setQuery('q_1741581729');" onmouseover="showSample('q_1741581729',this);" onmouseout="cjhideqs();">Using BETWEEN</a></div>
<div><a href="#" onclick="setQuery('q_293030657');" onmouseover="showSample('q_293030657',this);" onmouseout="cjhideqs();">Moving asteroids</a></div>
<div><a href="#" onclick="setQuery('q_50066576');" onmouseover="showSample('q_50066576',this);" onmouseout="cjhideqs();">Quasars in imaging</a></div>
<div><a href="#" onclick="setQuery('q_1227312257');" onmouseover="showSample('q_1227312257',this);" onmouseout="cjhideqs();">Object counts and logic</a></div>
<div><a href="#" onclick="setQuery('q_1009123441');" onmouseover="showSample('q_1009123441',this);" onmouseout="cjhideqs();">Galaxy star blends</a></div>
<div><a href="#" onclick="setQuery('q_97947386');" onmouseover="showSample('q_97947386',this);" onmouseout="cjhideqs();">Stars in specific fields</a></div>
<div><a href="#" onclick="setQuery('q_1715812784');" onmouseover="showSample('q_1715812784',this);" onmouseout="cjhideqs();">Using three tables</a></div>
<div><a href="#" onclick="setQuery('q_1301593803');" onmouseover="showSample('q_1301593803',this);" onmouseout="cjhideqs();">Objects close pairs</a></div>
<div><a href="#" onclick="setQuery('q_1729284068');" onmouseover="showSample('q_1729284068',this);" onmouseout="cjhideqs();">QSOs in spectroscopy</a></div>
<div><a href="#" onclick="setQuery('q_1709778956');" onmouseover="showSample('q_1709778956',this);" onmouseout="cjhideqs();">Errors using flags</a></div>
<div><a href="#" onclick="setQuery('q_1346173317');" onmouseover="showSample('q_1346173317',this);" onmouseout="cjhideqs();">Elliptical galaxies</a></div>
<div><a href="#" onclick="setQuery('q_874416063');" onmouseover="showSample('q_874416063',this);" onmouseout="cjhideqs();">Galaxies blue centers</a></div>
<div><a href="#" onclick="setQuery('q_1426553339');" onmouseover="showSample('q_1426553339',this);" onmouseout="cjhideqs();">Diameter limited galaxies</a></div>
<div><a href="#" onclick="setQuery('q_2092933015');" onmouseover="showSample('q_2092933015',this);" onmouseout="cjhideqs();">Extremely red galaxies</a></div>
<div><a href="#" onclick="setQuery('q_2046005064');" onmouseover="showSample('q_2046005064',this);" onmouseout="cjhideqs();">LRG sample</a></div>
<div><a href="#" onclick="setQuery('q_1937139908');" onmouseover="showSample('q_1937139908',this);" onmouseout="cjhideqs();">Galaxies by spectra</a></div>
<div><a href="#" onclick="setQuery('q_1071911477');" onmouseover="showSample('q_1071911477',this);" onmouseout="cjhideqs();">Galaxies by spectra2</a></div>
<div><a href="#" onclick="setQuery('q_1639576493');" onmouseover="showSample('q_1639576493',this);" onmouseout="cjhideqs();">Binary stars colors</a></div>
<div><a href="#" onclick="setQuery('q_2052665602');" onmouseover="showSample('q_2052665602',this);" onmouseout="cjhideqs();">QSOs broadlines near galaxy</a></div>
<div><a href="#" onclick="setQuery('q_1227456513');" onmouseover="showSample('q_1227456513',this);" onmouseout="cjhideqs();">Galaxies unsaturated near coord</a></div>
<div><a href="#" onclick="setQuery('q_1795100394');" onmouseover="showSample('q_1795100394',this);" onmouseout="cjhideqs();">Ellipticals odd lines</a></div>
<div><a href="#" onclick="setQuery('q_1993463533');" onmouseover="showSample('q_1993463533',this);" onmouseout="cjhideqs();">Search near BCGs</a></div>
<div><a href="#" onclick="setQuery('q_477859480');" onmouseover="showSample('q_477859480',this);" onmouseout="cjhideqs();">Broadest spectral lines</a></div>
<div><a href="#" onclick="setQuery('q_1558845305');" onmouseover="showSample('q_1558845305',this);" onmouseout="cjhideqs();">Gridded galaxy counts</a></div>
<div><a href="#" onclick="setQuery('q_30651545');" onmouseover="showSample('q_30651545',this);" onmouseout="cjhideqs();">Galaxy counts HTM grid</a></div>
<div><a href="#" onclick="setQuery('q_598412421');" onmouseover="showSample('q_598412421',this);" onmouseout="cjhideqs();">Stars multiply measured</a></div>
<div><a href="#" onclick="setQuery('q_834106047');" onmouseover="showSample('q_834106047',this);" onmouseout="cjhideqs();">Checking SDSS footprint</a></div>
</div>
<div id="dr4_samples">
<div><a href="#" onclick="setQuery('q_190266330');" onmouseover="showSample('q_190266330',this);" onmouseout="cjhideqs();">Basic SELECT FROM WHERE</a></div>
<div><a href="#" onclick="setQuery('q_399748022');" onmouseover="showSample('q_399748022',this);" onmouseout="cjhideqs();">Galaxies two criteria</a></div>
<div><a href="#" onclick="setQuery('q_168487273');" onmouseover="showSample('q_168487273',this);" onmouseout="cjhideqs();">Unclassified spectra</a></div>
<div><a href="#" onclick="setQuery('q_1315505534');" onmouseover="showSample('q_1315505534',this);" onmouseout="cjhideqs();">Galaxies multiple criteria</a></div>
<div><a href="#" onclick="setQuery('q_1675888762');" onmouseover="showSample('q_1675888762',this);" onmouseout="cjhideqs();">Spatial unit vectors</a></div>
<div><a href="#" onclick="setQuery('q_1650901083');" onmouseover="showSample('q_1650901083',this);" onmouseout="cjhideqs();">CVs using colors</a></div>
<div><a href="#" onclick="setQuery('q_763893289');" onmouseover="showSample('q_763893289',this);" onmouseout="cjhideqs();">Data subsample</a></div>
<div><a href="#" onclick="setQuery('q_1725633998');" onmouseover="showSample('q_1725633998',this);" onmouseout="cjhideqs();">Low z QSOs by colors</a></div>
<div><a href="#" onclick="setQuery('q_1178472613');" onmouseover="showSample('q_1178472613',this);" onmouseout="cjhideqs();">Velocities and errors</a></div>
<div><a href="#" onclick="setQuery('q_828709702');" onmouseover="showSample('q_828709702',this);" onmouseout="cjhideqs();">Using BETWEEN</a></div>
<div><a href="#" onclick="setQuery('q_1055252390');" onmouseover="showSample('q_1055252390',this);" onmouseout="cjhideqs();">Moving asteroids</a></div>
<div><a href="#" onclick="setQuery('q_791936939');" onmouseover="showSample('q_791936939',this);" onmouseout="cjhideqs();">Quasars in imaging</a></div>
<div><a href="#" onclick="setQuery('q_224126374');" onmouseover="showSample('q_224126374',this);" onmouseout="cjhideqs();">Object counts and logic</a></div>
<div><a href="#" onclick="setQuery('q_388139904');" onmouseover="showSample('q_388139904',this);" onmouseout="cjhideqs();">Galaxy star blends</a></div>
<div><a href="#" onclick="setQuery('q_915208631');" onmouseover="showSample('q_915208631',this);" onmouseout="cjhideqs();">Stars in specific fields</a></div>
<div><a href="#" onclick="setQuery('q_98652983');" onmouseover="showSample('q_98652983',this);" onmouseout="cjhideqs();">Using three tables</a></div>
<div><a href="#" onclick="setQuery('q_2027172584');" onmouseover="showSample('q_2027172584',this);" onmouseout="cjhideqs();">Objects close pairs</a></div>
<div><a href="#" onclick="setQuery('q_730255691');" onmouseover="showSample('q_730255691',this);" onmouseout="cjhideqs();">QSOs in spectroscopy</a></div>
<div><a href="#" onclick="setQuery('q_1691326363');" onmouseover="showSample('q_1691326363',this);" onmouseout="cjhideqs();">Errors using flags</a></div>
<div><a href="#" onclick="setQuery('q_1324808024');" onmouseover="showSample('q_1324808024',this);" onmouseout="cjhideqs();">Elliptical galaxies</a></div>
<div><a href="#" onclick="setQuery('q_51406064');" onmouseover="showSample('q_51406064',this);" onmouseout="cjhideqs();">Galaxies blue centers</a></div>
<div><a href="#" onclick="setQuery('q_1713458572');" onmouseover="showSample('q_1713458572',this);" onmouseout="cjhideqs();">Diameter limited galaxies</a></div>
<div><a href="#" onclick="setQuery('q_70783942');" onmouseover="showSample('q_70783942',this);" onmouseout="cjhideqs();">Extremely red galaxies</a></div>
<div><a href="#" onclick="setQuery('q_1804705991');" onmouseover="showSample('q_1804705991',this);" onmouseout="cjhideqs();">LRG sample</a></div>
<div><a href="#" onclick="setQuery('q_167002323');" onmouseover="showSample('q_167002323',this);" onmouseout="cjhideqs();">Galaxies by spectra</a></div>
<div><a href="#" onclick="setQuery('q_834596942');" onmouseover="showSample('q_834596942',this);" onmouseout="cjhideqs();">Galaxies by spectra2</a></div>
<div><a href="#" onclick="setQuery('q_1424444742');" onmouseover="showSample('q_1424444742',this);" onmouseout="cjhideqs();">Binary stars colors</a></div>
<div><a href="#" onclick="setQuery('q_175511087');" onmouseover="showSample('q_175511087',this);" onmouseout="cjhideqs();">QSOs broadlines near galaxy</a></div>
<div><a href="#" onclick="setQuery('q_1053909050');" onmouseover="showSample('q_1053909050',this);" onmouseout="cjhideqs();">Galaxies unsaturated near coord</a></div>
<div><a href="#" onclick="setQuery('q_622853371');" onmouseover="showSample('q_622853371',this);" onmouseout="cjhideqs();">Ellipticals odd lines</a></div>
<div><a href="#" onclick="setQuery('q_510380354');" onmouseover="showSample('q_510380354',this);" onmouseout="cjhideqs();">Search near BCGs</a></div>
<div><a href="#" onclick="setQuery('q_963813061');" onmouseover="showSample('q_963813061',this);" onmouseout="cjhideqs();">Broadest spectral lines</a></div>
<div><a href="#" onclick="setQuery('q_23925016');" onmouseover="showSample('q_23925016',this);" onmouseout="cjhideqs();">Gridded galaxy counts</a></div>
<div><a href="#" onclick="setQuery('q_1398357282');" onmouseover="showSample('q_1398357282',this);" onmouseout="cjhideqs();">Galaxy counts HTM grid</a></div>
<div><a href="#" onclick="setQuery('q_1944663326');" onmouseover="showSample('q_1944663326',this);" onmouseout="cjhideqs();">Stars multiply measured</a></div>
<div><a href="#" onclick="setQuery('q_166816670');" onmouseover="showSample('q_166816670',this);" onmouseout="cjhideqs();">Checking SDSS footprint</a></div>
</div>
<div id="dr5_samples">
<div><a href="#" onclick="setQuery('q_314022943');" onmouseover="showSample('q_314022943',this);" onmouseout="cjhideqs();">Basic SELECT FROM WHERE</a></div>
<div><a href="#" onclick="setQuery('q_2121237275');" onmouseover="showSample('q_2121237275',this);" onmouseout="cjhideqs();">Galaxies two criteria</a></div>
<div><a href="#" onclick="setQuery('q_706908036');" onmouseover="showSample('q_706908036',this);" onmouseout="cjhideqs();">Unclassified spectra</a></div>
<div><a href="#" onclick="setQuery('q_1510674311');" onmouseover="showSample('q_1510674311',this);" onmouseout="cjhideqs();">Galaxies multiple criteria</a></div>
<div><a href="#" onclick="setQuery('q_342684245');" onmouseover="showSample('q_342684245',this);" onmouseout="cjhideqs();">Spatial unit vectors</a></div>
<div><a href="#" onclick="setQuery('q_1821885322');" onmouseover="showSample('q_1821885322',this);" onmouseout="cjhideqs();">CVs using colors</a></div>
<div><a href="#" onclick="setQuery('q_654356252');" onmouseover="showSample('q_654356252',this);" onmouseout="cjhideqs();">Data subsample</a></div>
<div><a href="#" onclick="setQuery('q_420853709');" onmouseover="showSample('q_420853709',this);" onmouseout="cjhideqs();">Low z QSOs by colors</a></div>
<div><a href="#" onclick="setQuery('q_631175478');" onmouseover="showSample('q_631175478',this);" onmouseout="cjhideqs();">Velocities and errors</a></div>
<div><a href="#" onclick="setQuery('q_1165868693');" onmouseover="showSample('q_1165868693',this);" onmouseout="cjhideqs();">Using BETWEEN</a></div>
<div><a href="#" onclick="setQuery('q_1514903499');" onmouseover="showSample('q_1514903499',this);" onmouseout="cjhideqs();">Moving asteroids</a></div>
<div><a href="#" onclick="setQuery('q_214576614');" onmouseover="showSample('q_214576614',this);" onmouseout="cjhideqs();">Quasars in imaging</a></div>
<div><a href="#" onclick="setQuery('q_619033119');" onmouseover="showSample('q_619033119',this);" onmouseout="cjhideqs();">Object counts and logic</a></div>
<div><a href="#" onclick="setQuery('q_1653404421');" onmouseover="showSample('q_1653404421',this);" onmouseout="cjhideqs();">Galaxy star blends</a></div>
<div><a href="#" onclick="setQuery('q_1527039772');" onmouseover="showSample('q_1527039772',this);" onmouseout="cjhideqs();">Stars in specific fields</a></div>
<div><a href="#" onclick="setQuery('q_1055015502');" onmouseover="showSample('q_1055015502',this);" onmouseout="cjhideqs();">Using three tables</a></div>
<div><a href="#" onclick="setQuery('q_1131150381');" onmouseover="showSample('q_1131150381',this);" onmouseout="cjhideqs();">Objects close pairs</a></div>
<div><a href="#" onclick="setQuery('q_859289958');" onmouseover="showSample('q_859289958',this);" onmouseout="cjhideqs();">QSOs in spectroscopy</a></div>
<div><a href="#" onclick="setQuery('q_1033172010');" onmouseover="showSample('q_1033172010',this);" onmouseout="cjhideqs();">Errors using flags</a></div>
<div><a href="#" onclick="setQuery('q_976449187');" onmouseover="showSample('q_976449187',this);" onmouseout="cjhideqs();">Elliptical galaxies</a></div>
<div><a href="#" onclick="setQuery('q_1404790795');" onmouseover="showSample('q_1404790795',this);" onmouseout="cjhideqs();">Galaxies blue centers</a></div>
<div><a href="#" onclick="setQuery('q_1368831015');" onmouseover="showSample('q_1368831015',this);" onmouseout="cjhideqs();">Diameter limited galaxies</a></div>
<div><a href="#" onclick="setQuery('q_642208693');" onmouseover="showSample('q_642208693',this);" onmouseout="cjhideqs();">Extremely red galaxies</a></div>
<div><a href="#" onclick="setQuery('q_674238270');" onmouseover="showSample('q_674238270',this);" onmouseout="cjhideqs();">LRG sample</a></div>
<div><a href="#" onclick="setQuery('q_1020817074');" onmouseover="showSample('q_1020817074',this);" onmouseout="cjhideqs();">Galaxies by spectra</a></div>
<div><a href="#" onclick="setQuery('q_1695980969');" onmouseover="showSample('q_1695980969',this);" onmouseout="cjhideqs();">Galaxies by spectra2</a></div>
<div><a href="#" onclick="setQuery('q_1794028875');" onmouseover="showSample('q_1794028875',this);" onmouseout="cjhideqs();">Binary stars colors</a></div>
<div><a href="#" onclick="setQuery('q_875447540');" onmouseover="showSample('q_875447540',this);" onmouseout="cjhideqs();">QSOs broadlines near galaxy</a></div>
<div><a href="#" onclick="setQuery('q_408046859');" onmouseover="showSample('q_408046859',this);" onmouseout="cjhideqs();">Galaxies unsaturated near coord</a></div>
<div><a href="#" onclick="setQuery('q_2023911456');" onmouseover="showSample('q_2023911456',this);" onmouseout="cjhideqs();">Ellipticals odd lines</a></div>
<div><a href="#" onclick="setQuery('q_1739829469');" onmouseover="showSample('q_1739829469',this);" onmouseout="cjhideqs();">Search near BCGs</a></div>
<div><a href="#" onclick="setQuery('q_1716646730');" onmouseover="showSample('q_1716646730',this);" onmouseout="cjhideqs();">Broadest spectral lines</a></div>
<div><a href="#" onclick="setQuery('q_856840643');" onmouseover="showSample('q_856840643',this);" onmouseout="cjhideqs();">Gridded galaxy counts</a></div>
<div><a href="#" onclick="setQuery('q_211714083');" onmouseover="showSample('q_211714083',this);" onmouseout="cjhideqs();">Galaxy counts HTM grid</a></div>
<div><a href="#" onclick="setQuery('q_137356135');" onmouseover="showSample('q_137356135',this);" onmouseout="cjhideqs();">Stars multiply measured</a></div>
<div><a href="#" onclick="setQuery('q_1480779043');" onmouseover="showSample('q_1480779043',this);" onmouseout="cjhideqs();">Checking SDSS footprint</a></div>
</div>
<div id="dr6_samples">
<div><a href="#" onclick="setQuery('q_1195248688');" onmouseover="showSample('q_1195248688',this);" onmouseout="cjhideqs();">Basic SELECT FROM WHERE</a></div>
<div><a href="#" onclick="setQuery('q_1747257364');" onmouseover="showSample('q_1747257364',this);" onmouseout="cjhideqs();">Galaxies two criteria</a></div>
<div><a href="#" onclick="setQuery('q_1374627809');" onmouseover="showSample('q_1374627809',this);" onmouseout="cjhideqs();">Unclassified spectra</a></div>
<div><a href="#" onclick="setQuery('q_1381525768');" onmouseover="showSample('q_1381525768',this);" onmouseout="cjhideqs();">Galaxies multiple criteria</a></div>
<div><a href="#" onclick="setQuery('q_909071920');" onmouseover="showSample('q_909071920',this);" onmouseout="cjhideqs();">Spatial unit vectors</a></div>
<div><a href="#" onclick="setQuery('q_1357802971');" onmouseover="showSample('q_1357802971',this);" onmouseout="cjhideqs();">CVs using colors</a></div>
<div><a href="#" onclick="setQuery('q_1954141537');" onmouseover="showSample('q_1954141537',this);" onmouseout="cjhideqs();">Data subsample</a></div>
<div><a href="#" onclick="setQuery('q_545014296');" onmouseover="showSample('q_545014296',this);" onmouseout="cjhideqs();">Low z QSOs by colors</a></div>
<div><a href="#" onclick="setQuery('q_547865327');" onmouseover="showSample('q_547865327',this);" onmouseout="cjhideqs();">Velocities and errors</a></div>
<div><a href="#" onclick="setQuery('q_716142064');" onmouseover="showSample('q_716142064',this);" onmouseout="cjhideqs();">Using BETWEEN</a></div>
<div><a href="#" onclick="setQuery('q_272200048');" onmouseover="showSample('q_272200048',this);" onmouseout="cjhideqs();">Moving asteroids</a></div>
<div><a href="#" onclick="setQuery('q_753648351');" onmouseover="showSample('q_753648351',this);" onmouseout="cjhideqs();">Quasars in imaging</a></div>
<div><a href="#" onclick="setQuery('q_1150951472');" onmouseover="showSample('q_1150951472',this);" onmouseout="cjhideqs();">Object counts and logic</a></div>
<div><a href="#" onclick="setQuery('q_106085622');" onmouseover="showSample('q_106085622',this);" onmouseout="cjhideqs();">Galaxy star blends</a></div>
<div><a href="#" onclick="setQuery('q_1713017857');" onmouseover="showSample('q_1713017857',this);" onmouseout="cjhideqs();">Stars in specific fields</a></div>
<div><a href="#" onclick="setQuery('q_270075329');" onmouseover="showSample('q_270075329',this);" onmouseout="cjhideqs();">Using three tables</a></div>
<div><a href="#" onclick="setQuery('q_1540370546');" onmouseover="showSample('q_1540370546',this);" onmouseout="cjhideqs();">Objects close pairs</a></div>
<div><a href="#" onclick="setQuery('q_365239915');" onmouseover="showSample('q_365239915',this);" onmouseout="cjhideqs();">QSOs in spectroscopy</a></div>
<div><a href="#" onclick="setQuery('q_179278427');" onmouseover="showSample('q_179278427',this);" onmouseout="cjhideqs();">Errors using flags</a></div>
<div><a href="#" onclick="setQuery('q_2005973150');" onmouseover="showSample('q_2005973150',this);" onmouseout="cjhideqs();">Elliptical galaxies</a></div>
<div><a href="#" onclick="setQuery('q_1400899770');" onmouseover="showSample('q_1400899770',this);" onmouseout="cjhideqs();">Galaxies blue centers</a></div>
<div><a href="#" onclick="setQuery('q_1330058026');" onmouseover="showSample('q_1330058026',this);" onmouseout="cjhideqs();">Diameter limited galaxies</a></div>
<div><a href="#" onclick="setQuery('q_1048676048');" onmouseover="showSample('q_1048676048',this);" onmouseout="cjhideqs();">Extremely red galaxies</a></div>
<div><a href="#" onclick="setQuery('q_53648337');" onmouseover="showSample('q_53648337',this);" onmouseout="cjhideqs();">LRG sample</a></div>
<div><a href="#" onclick="setQuery('q_1793902941');" onmouseover="showSample('q_1793902941',this);" onmouseout="cjhideqs();">Galaxies by spectra</a></div>
<div><a href="#" onclick="setQuery('q_1876907516');" onmouseover="showSample('q_1876907516',this);" onmouseout="cjhideqs();">Galaxies by spectra2</a></div>
<div><a href="#" onclick="setQuery('q_1499026876');" onmouseover="showSample('q_1499026876',this);" onmouseout="cjhideqs();">Binary stars colors</a></div>
<div><a href="#" onclick="setQuery('q_253037019');" onmouseover="showSample('q_253037019',this);" onmouseout="cjhideqs();">QSOs broadlines near galaxy</a></div>
<div><a href="#" onclick="setQuery('q_627065552');" onmouseover="showSample('q_627065552',this);" onmouseout="cjhideqs();">Galaxies unsaturated near coord</a></div>
<div><a href="#" onclick="setQuery('q_873473743');" onmouseover="showSample('q_873473743',this);" onmouseout="cjhideqs();">Ellipticals odd lines</a></div>
<div><a href="#" onclick="setQuery('q_1226072052');" onmouseover="showSample('q_1226072052',this);" onmouseout="cjhideqs();">Search near BCGs</a></div>
<div><a href="#" onclick="setQuery('q_1201934799');" onmouseover="showSample('q_1201934799',this);" onmouseout="cjhideqs();">Broadest spectral lines</a></div>
<div><a href="#" onclick="setQuery('q_1778610482');" onmouseover="showSample('q_1778610482',this);" onmouseout="cjhideqs();">Gridded galaxy counts</a></div>
<div><a href="#" onclick="setQuery('q_2026496616');" onmouseover="showSample('q_2026496616',this);" onmouseout="cjhideqs();">Galaxy counts HTM grid</a></div>
<div><a href="#" onclick="setQuery('q_813213932');" onmouseover="showSample('q_813213932',this);" onmouseout="cjhideqs();">Stars multiply measured</a></div>
<div><a href="#" onclick="setQuery('q_1470069848');" onmouseover="showSample('q_1470069848',this);" onmouseout="cjhideqs();">Checking SDSS footprint</a></div>
</div>
<div id="dr7_samples">
<div><a href="#" onclick="setQuery('q_1442356757');" onmouseover="showSample('q_1442356757',this);" onmouseout="cjhideqs();">Basic SELECT FROM WHERE</a></div>
<div><a href="#" onclick="setQuery('q_25768111');" onmouseover="showSample('q_25768111',this);" onmouseout="cjhideqs();">Galaxies two criteria</a></div>
<div><a href="#" onclick="setQuery('q_836207046');" onmouseover="showSample('q_836207046',this);" onmouseout="cjhideqs();">Unclassified spectra</a></div>
<div><a href="#" onclick="setQuery('q_1444654077');" onmouseover="showSample('q_1444654077',this);" onmouseout="cjhideqs();">Galaxies multiple criteria</a></div>
<div><a href="#" onclick="setQuery('q_824393739');" onmouseover="showSample('q_824393739',this);" onmouseout="cjhideqs();">Spatial unit vectors</a></div>
<div><a href="#" onclick="setQuery('q_1467158080');" onmouseover="showSample('q_1467158080',this);" onmouseout="cjhideqs();">CVs using colors</a></div>
<div><a href="#" onclick="setQuery('q_922576218');" onmouseover="showSample('q_922576218',this);" onmouseout="cjhideqs();">Data subsample</a></div>
<div><a href="#" onclick="setQuery('q_256345731');" onmouseover="showSample('q_256345731',this);" onmouseout="cjhideqs();">Low z QSOs by colors</a></div>
<div><a href="#" onclick="setQuery('q_1261782764');" onmouseover="showSample('q_1261782764',this);" onmouseout="cjhideqs();">Velocities and errors</a></div>
<div><a href="#" onclick="setQuery('q_1772065995');" onmouseover="showSample('q_1772065995',this);" onmouseout="cjhideqs();">Using BETWEEN</a></div>
<div><a href="#" onclick="setQuery('q_731851157');" onmouseover="showSample('q_731851157',this);" onmouseout="cjhideqs();">Moving asteroids</a></div>
<div><a href="#" onclick="setQuery('q_197942948');" onmouseover="showSample('q_197942948',this);" onmouseout="cjhideqs();">Quasars in imaging</a></div>
<div><a href="#" onclick="setQuery('q_307791979');" onmouseover="showSample('q_307791979',this);" onmouseout="cjhideqs();">Object counts and logic</a></div>
<div><a href="#" onclick="setQuery('q_663453829');" onmouseover="showSample('q_663453829',this);" onmouseout="cjhideqs();">Galaxy star blends</a></div>
<div><a href="#" onclick="setQuery('q_1970118298');" onmouseover="showSample('q_1970118298',this);" onmouseout="cjhideqs();">Stars in specific fields</a></div>
<div><a href="#" onclick="setQuery('q_1322104004');" onmouseover="showSample('q_1322104004',this);" onmouseout="cjhideqs();">Using three tables</a></div>
<div><a href="#" onclick="setQuery('q_488717385');" onmouseover="showSample('q_488717385',this);" onmouseout="cjhideqs();">Objects close pairs</a></div>
<div><a href="#" onclick="setQuery('q_666094160');" onmouseover="showSample('q_666094160',this);" onmouseout="cjhideqs();">QSOs in spectroscopy</a></div>
<div><a href="#" onclick="setQuery('q_1391190496');" onmouseover="showSample('q_1391190496',this);" onmouseout="cjhideqs();">Errors using flags</a></div>
<div><a href="#" onclick="setQuery('q_12263065');" onmouseover="showSample('q_12263065',this);" onmouseout="cjhideqs();">Elliptical galaxies</a></div>
<div><a href="#" onclick="setQuery('q_1540682795');" onmouseover="showSample('q_1540682795',this);" onmouseout="cjhideqs();">Galaxies blue centers</a></div>
<div><a href="#" onclick="setQuery('q_1674685583');" onmouseover="showSample('q_1674685583',this);" onmouseout="cjhideqs();">Diameter limited galaxies</a></div>
<div><a href="#" onclick="setQuery('q_335683413');" onmouseover="showSample('q_335683413',this);" onmouseout="cjhideqs();">Extremely red galaxies</a></div>
<div><a href="#" onclick="setQuery('q_1986785076');" onmouseover="showSample('q_1986785076',this);" onmouseout="cjhideqs();">LRG sample</a></div>
<div><a href="#" onclick="setQuery('q_279312168');" onmouseover="showSample('q_279312168',this);" onmouseout="cjhideqs();">Galaxies by spectra</a></div>
<div><a href="#" onclick="setQuery('q_168810913');" onmouseover="showSample('q_168810913',this);" onmouseout="cjhideqs();">Galaxies by spectra2</a></div>
<div><a href="#" onclick="setQuery('q_1868611009');" onmouseover="showSample('q_1868611009',this);" onmouseout="cjhideqs();">Binary stars colors</a></div>
<div><a href="#" onclick="setQuery('q_686166294');" onmouseover="showSample('q_686166294',this);" onmouseout="cjhideqs();">QSOs broadlines near galaxy</a></div>
<div><a href="#" onclick="setQuery('q_2089021461');" onmouseover="showSample('q_2089021461',this);" onmouseout="cjhideqs();">Galaxies unsaturated near coord</a></div>
<div><a href="#" onclick="setQuery('q_535089494');" onmouseover="showSample('q_535089494',this);" onmouseout="cjhideqs();">Ellipticals odd lines</a></div>
<div><a href="#" onclick="setQuery('q_1581828007');" onmouseover="showSample('q_1581828007',this);" onmouseout="cjhideqs();">Search near BCGs</a></div>
<div><a href="#" onclick="setQuery('q_1954768468');" onmouseover="showSample('q_1954768468',this);" onmouseout="cjhideqs();">Broadest spectral lines</a></div>
<div><a href="#" onclick="setQuery('q_1311402765');" onmouseover="showSample('q_1311402765',this);" onmouseout="cjhideqs();">Gridded galaxy counts</a></div>
<div><a href="#" onclick="setQuery('q_1594656083');" onmouseover="showSample('q_1594656083',this);" onmouseout="cjhideqs();">Galaxy counts HTM grid</a></div>
<div><a href="#" onclick="setQuery('q_1399733903');" onmouseover="showSample('q_1399733903',this);" onmouseout="cjhideqs();">Stars multiply measured</a></div>
<div><a href="#" onclick="setQuery('q_532479277');" onmouseover="showSample('q_532479277',this);" onmouseout="cjhideqs();">Checking SDSS footprint</a></div>
</div>
<div id="dr8_samples">
<div><a href="#" onclick="setQuery('q_1774811490');" onmouseover="showSample('q_1774811490',this);" onmouseout="cjhideqs();">Basic SELECT FROM WHERE</a></div>
<div><a href="#" onclick="setQuery('q_1950906038');" onmouseover="showSample('q_1950906038',this);" onmouseout="cjhideqs();">Galaxies two criteria</a></div>
<div><a href="#" onclick="setQuery('q_118442681');" onmouseover="showSample('q_118442681',this);" onmouseout="cjhideqs();">QSOs in spectroscopy</a></div>
<div><a href="#" onclick="setQuery('q_1087655456');" onmouseover="showSample('q_1087655456',this);" onmouseout="cjhideqs();">Using BETWEEN</a></div>
<div><a href="#" onclick="setQuery('q_1315557362');" onmouseover="showSample('q_1315557362',this);" onmouseout="cjhideqs();">Spatial unit vectors</a></div>
<div><a href="#" onclick="setQuery('q_671661625');" onmouseover="showSample('q_671661625',this);" onmouseout="cjhideqs();">CVs using colors</a></div>
<div><a href="#" onclick="setQuery('q_474354453');" onmouseover="showSample('q_474354453',this);" onmouseout="cjhideqs();">Data subsample</a></div>
<div><a href="#" onclick="setQuery('q_765492618');" onmouseover="showSample('q_765492618',this);" onmouseout="cjhideqs();">Low z QSOs by colors</a></div>
<div><a href="#" onclick="setQuery('q_453245167');" onmouseover="showSample('q_453245167',this);" onmouseout="cjhideqs();">Velocities and errors</a></div>
<div><a href="#" onclick="setQuery('q_1745962591');" onmouseover="showSample('q_1745962591',this);" onmouseout="cjhideqs();">Galaxies By Emission Lines</a></div>
<div><a href="#" onclick="setQuery('q_23566870');" onmouseover="showSample('q_23566870',this);" onmouseout="cjhideqs();">Moving asteroids</a></div>
<div><a href="#" onclick="setQuery('q_225105383');" onmouseover="showSample('q_225105383',this);" onmouseout="cjhideqs();">Quasars in imaging</a></div>
<div><a href="#" onclick="setQuery('q_834528110');" onmouseover="showSample('q_834528110',this);" onmouseout="cjhideqs();">Object counts and logic</a></div>
<div><a href="#" onclick="setQuery('q_245836436');" onmouseover="showSample('q_245836436',this);" onmouseout="cjhideqs();">Galaxy star blends</a></div>
<div><a href="#" onclick="setQuery('q_1952789469');" onmouseover="showSample('q_1952789469',this);" onmouseout="cjhideqs();">Stars in specific fields</a></div>
<div><a href="#" onclick="setQuery('q_1577813389');" onmouseover="showSample('q_1577813389',this);" onmouseout="cjhideqs();">Using three tables</a></div>
<div><a href="#" onclick="setQuery('q_1362554404');" onmouseover="showSample('q_1362554404',this);" onmouseout="cjhideqs();">Objects close pairs</a></div>
<div><a href="#" onclick="setQuery('q_1335992021');" onmouseover="showSample('q_1335992021',this);" onmouseout="cjhideqs();">Stars multiply measured</a></div>
<div><a href="#" onclick="setQuery('q_999622185');" onmouseover="showSample('q_999622185',this);" onmouseout="cjhideqs();">Errors using flags</a></div>
<div><a href="#" onclick="setQuery('q_416441924');" onmouseover="showSample('q_416441924',this);" onmouseout="cjhideqs();">Elliptical galaxies</a></div>
<div><a href="#" onclick="setQuery('q_2043177420');" onmouseover="showSample('q_2043177420',this);" onmouseout="cjhideqs();">Galaxies blue centers</a></div>
<div><a href="#" onclick="setQuery('q_538360056');" onmouseover="showSample('q_538360056',this);" onmouseout="cjhideqs();">Diameter limited galaxies</a></div>
<div><a href="#" onclick="setQuery('q_1596667058');" onmouseover="showSample('q_1596667058',this);" onmouseout="cjhideqs();">Extremely red galaxies</a></div>
<div><a href="#" onclick="setQuery('q_1317231909');" onmouseover="showSample('q_1317231909',this);" onmouseout="cjhideqs();">LRG sample</a></div>
<div><a href="#" onclick="setQuery('q_1838668250');" onmouseover="showSample('q_1838668250',this);" onmouseout="cjhideqs();">Spectra of Red Stars</a></div>
<div><a href="#" onclick="setQuery('q_2014769771');" onmouseover="showSample('q_2014769771',this);" onmouseout="cjhideqs();">Galaxy counts HTM grid</a></div>
<div><a href="#" onclick="setQuery('q_1687012106');" onmouseover="showSample('q_1687012106',this);" onmouseout="cjhideqs();">Binary stars colors</a></div>
<div><a href="#" onclick="setQuery('q_1632881509');" onmouseover="showSample('q_1632881509',this);" onmouseout="cjhideqs();">Galaxies unsaturated near coord</a></div>
<div><a href="#" onclick="setQuery('q_103654135');" onmouseover="showSample('q_103654135',this);" onmouseout="cjhideqs();">Search near BCGs</a></div>
<div><a href="#" onclick="setQuery('q_675428088');" onmouseover="showSample('q_675428088',this);" onmouseout="cjhideqs();">Multiple Detections and Time Series</a></div>
</div>
<div id="dr9_samples">
<div><a href="#" onclick="setQuery('q_1651054877');" onmouseover="showSample('q_1651054877',this);" onmouseout="cjhideqs();">Basic SELECT FROM WHERE</a></div>
<div><a href="#" onclick="setQuery('q_229416785');" onmouseover="showSample('q_229416785',this);" onmouseout="cjhideqs();">Galaxies two criteria</a></div>
<div><a href="#" onclick="setQuery('q_639018260');" onmouseover="showSample('q_639018260',this);" onmouseout="cjhideqs();">QSOs in spectroscopy</a></div>
<div><a href="#" onclick="setQuery('q_906922939');" onmouseover="showSample('q_906922939',this);" onmouseout="cjhideqs();">Using BETWEEN</a></div>
<div><a href="#" onclick="setQuery('q_1646205417');" onmouseover="showSample('q_1646205417',this);" onmouseout="cjhideqs();">Spatial unit vectors</a></div>
<div><a href="#" onclick="setQuery('q_150519266');" onmouseover="showSample('q_150519266',this);" onmouseout="cjhideqs();">CVs using colors</a></div>
<div><a href="#" onclick="setQuery('q_943895088');" onmouseover="showSample('q_943895088',this);" onmouseout="cjhideqs();">Data subsample</a></div>
<div><a href="#" onclick="setQuery('q_1380995089');" onmouseover="showSample('q_1380995089',this);" onmouseout="cjhideqs();">Low z QSOs by colors</a></div>
<div><a href="#" onclick="setQuery('q_2032074038');" onmouseover="showSample('q_2032074038',this);" onmouseout="cjhideqs();">Velocities and errors</a></div>
<div><a href="#" onclick="setQuery('q_77418842');" onmouseover="showSample('q_77418842',this);" onmouseout="cjhideqs();">Galaxies By Emission Lines</a></div>
<div><a href="#" onclick="setQuery('q_436084239');" onmouseover="showSample('q_436084239',this);" onmouseout="cjhideqs();">Moving asteroids</a></div>
<div><a href="#" onclick="setQuery('q_352254942');" onmouseover="showSample('q_352254942',this);" onmouseout="cjhideqs();">Quasars in imaging</a></div>
<div><a href="#" onclick="setQuery('q_1677687603');" onmouseover="showSample('q_1677687603',this);" onmouseout="cjhideqs();">Object counts and logic</a></div>
<div><a href="#" onclick="setQuery('q_1019428081');" onmouseover="showSample('q_1019428081',this);" onmouseout="cjhideqs();">Galaxy star blends</a></div>
<div><a href="#" onclick="setQuery('q_1340958328');" onmouseover="showSample('q_1340958328',this);" onmouseout="cjhideqs();">Stars in specific fields</a></div>
<div><a href="#" onclick="setQuery('q_1563485422');" onmouseover="showSample('q_1563485422',this);" onmouseout="cjhideqs();">Using three tables</a></div>
<div><a href="#" onclick="setQuery('q_466532201');" onmouseover="showSample('q_466532201',this);" onmouseout="cjhideqs();">Objects close pairs</a></div>
<div><a href="#" onclick="setQuery('q_1381126224');" onmouseover="showSample('q_1381126224',this);" onmouseout="cjhideqs();">Stars multiply measured</a></div>
<div><a href="#" onclick="setQuery('q_570846738');" onmouseover="showSample('q_570846738',this);" onmouseout="cjhideqs();">Errors using flags</a></div>
<div><a href="#" onclick="setQuery('q_1884815287');" onmouseover="showSample('q_1884815287',this);" onmouseout="cjhideqs();">Elliptical galaxies</a></div>
<div><a href="#" onclick="setQuery('q_689792689');" onmouseover="showSample('q_689792689',this);" onmouseout="cjhideqs();">Galaxies blue centers</a></div>
<div><a href="#" onclick="setQuery('q_193732499');" onmouseover="showSample('q_193732499',this);" onmouseout="cjhideqs();">Diameter limited galaxies</a></div>
<div><a href="#" onclick="setQuery('q_883674423');" onmouseover="showSample('q_883674423',this);" onmouseout="cjhideqs();">Extremely red galaxies</a></div>
<div><a href="#" onclick="setQuery('q_498791126');" onmouseover="showSample('q_498791126',this);" onmouseout="cjhideqs();">LRG sample</a></div>
<div><a href="#" onclick="setQuery('q_620022539');" onmouseover="showSample('q_620022539',this);" onmouseout="cjhideqs();">Spectra of Red Stars</a></div>
<div><a href="#" onclick="setQuery('q_1606095120');" onmouseover="showSample('q_1606095120',this);" onmouseout="cjhideqs();">Galaxy counts HTM grid</a></div>
<div><a href="#" onclick="setQuery('q_2056596239');" onmouseover="showSample('q_2056596239',this);" onmouseout="cjhideqs();">Binary stars colors</a></div>
<div><a href="#" onclick="setQuery('q_1200129878');" onmouseover="showSample('q_1200129878',this);" onmouseout="cjhideqs();">Galaxies unsaturated near coord</a></div>
<div><a href="#" onclick="setQuery('q_1036893522');" onmouseover="showSample('q_1036893522',this);" onmouseout="cjhideqs();">Search near BCGs</a></div>
<div><a href="#" onclick="setQuery('q_1368842829');" onmouseover="showSample('q_1368842829',this);" onmouseout="cjhideqs();">Multiple Detections and Time Series</a></div>
</div>
<div id="dr9collab_samples">
<div><a href="#" onclick="setQuery('q_442485668');" onmouseover="showSample('q_442485668',this);" onmouseout="cjhideqs();">Basic SELECT FROM WHERE</a></div>
<div><a href="#" onclick="setQuery('q_2039614472');" onmouseover="showSample('q_2039614472',this);" onmouseout="cjhideqs();">Galaxies two criteria</a></div>
<div><a href="#" onclick="setQuery('q_1763264299');" onmouseover="showSample('q_1763264299',this);" onmouseout="cjhideqs();">QSOs in spectroscopy</a></div>
<div><a href="#" onclick="setQuery('q_2013120862');" onmouseover="showSample('q_2013120862',this);" onmouseout="cjhideqs();">Using BETWEEN</a></div>
<div><a href="#" onclick="setQuery('q_930225692');" onmouseover="showSample('q_930225692',this);" onmouseout="cjhideqs();">Spatial unit vectors</a></div>
<div><a href="#" onclick="setQuery('q_129227591');" onmouseover="showSample('q_129227591',this);" onmouseout="cjhideqs();">CVs using colors</a></div>
<div><a href="#" onclick="setQuery('q_1795754421');" onmouseover="showSample('q_1795754421',this);" onmouseout="cjhideqs();">Data subsample</a></div>
<div><a href="#" onclick="setQuery('q_787192452');" onmouseover="showSample('q_787192452',this);" onmouseout="cjhideqs();">Low z QSOs by colors</a></div>
<div><a href="#" onclick="setQuery('q_268548153');" onmouseover="showSample('q_268548153',this);" onmouseout="cjhideqs();">Velocities and errors</a></div>
<div><a href="#" onclick="setQuery('q_1047280483');" onmouseover="showSample('q_1047280483',this);" onmouseout="cjhideqs();">Galaxies By Emission Lines</a></div>
<div><a href="#" onclick="setQuery('q_191604836');" onmouseover="showSample('q_191604836',this);" onmouseout="cjhideqs();">Moving asteroids</a></div>
<div><a href="#" onclick="setQuery('q_1893814627');" onmouseover="showSample('q_1893814627',this);" onmouseout="cjhideqs();">Quasars in imaging</a></div>
<div><a href="#" onclick="setQuery('q_1199374736');" onmouseover="showSample('q_1199374736',this);" onmouseout="cjhideqs();">Object counts and logic</a></div>
<div><a href="#" onclick="setQuery('q_1733737046');" onmouseover="showSample('q_1733737046',this);" onmouseout="cjhideqs();">Galaxy star blends</a></div>
<div><a href="#" onclick="setQuery('q_317286293');" onmouseover="showSample('q_317286293',this);" onmouseout="cjhideqs();">Stars in specific fields</a></div>
<div><a href="#" onclick="setQuery('q_1874540969');" onmouseover="showSample('q_1874540969',this);" onmouseout="cjhideqs();">Using three tables</a></div>
<div><a href="#" onclick="setQuery('q_1435232814');" onmouseover="showSample('q_1435232814',this);" onmouseout="cjhideqs();">Objects close pairs</a></div>
<div><a href="#" onclick="setQuery('q_2060639971');" onmouseover="showSample('q_2060639971',this);" onmouseout="cjhideqs();">Stars multiply measured</a></div>
<div><a href="#" onclick="setQuery('q_1200416665');" onmouseover="showSample('q_1200416665',this);" onmouseout="cjhideqs();">Errors using flags</a></div>
<div><a href="#" onclick="setQuery('q_1563979474');" onmouseover="showSample('q_1563979474',this);" onmouseout="cjhideqs();">Elliptical galaxies</a></div>
<div><a href="#" onclick="setQuery('q_673740146');" onmouseover="showSample('q_673740146',this);" onmouseout="cjhideqs();">Galaxies blue centers</a></div>
<div><a href="#" onclick="setQuery('q_1080565066');" onmouseover="showSample('q_1080565066',this);" onmouseout="cjhideqs();">Diameter limited galaxies</a></div>
<div><a href="#" onclick="setQuery('q_1549277712');" onmouseover="showSample('q_1549277712',this);" onmouseout="cjhideqs();">Extremely red galaxies</a></div>
<div><a href="#" onclick="setQuery('q_1688445031');" onmouseover="showSample('q_1688445031',this);" onmouseout="cjhideqs();">LRG sample</a></div>
<div><a href="#" onclick="setQuery('q_1276987864');" onmouseover="showSample('q_1276987864',this);" onmouseout="cjhideqs();">Spectra of Red Stars</a></div>
<div><a href="#" onclick="setQuery('q_1804992033');" onmouseover="showSample('q_1804992033',this);" onmouseout="cjhideqs();">Galaxy counts HTM grid</a></div>
<div><a href="#" onclick="setQuery('q_1055302504');" onmouseover="showSample('q_1055302504',this);" onmouseout="cjhideqs();">Binary stars colors</a></div>
<div><a href="#" onclick="setQuery('q_183659941');" onmouseover="showSample('q_183659941',this);" onmouseout="cjhideqs();">Galaxies unsaturated near coord</a></div>
<div><a href="#" onclick="setQuery('q_2000917639');" onmouseover="showSample('q_2000917639',this);" onmouseout="cjhideqs();">Search near BCGs</a></div>
<div><a href="#" onclick="setQuery('q_359595534');" onmouseover="showSample('q_359595534',this);" onmouseout="cjhideqs();">Multiple Detections and Time Series</a></div>
</div>
<div id="weblog_samples">
<div><a href="#" onclick="setQuery('q_752833322');" onmouseover="showSample('q_752833322',this);" onmouseout="cjhideqs();">Monthly SQL Usage</a></div>
<div><a href="#" onclick="setQuery('q_652519058');" onmouseover="showSample('q_652519058',this);" onmouseout="cjhideqs();">Monthly GB Returned</a></div>
<div><a href="#" onclick="setQuery('q_518325890');" onmouseover="showSample('q_518325890',this);" onmouseout="cjhideqs();">Quarterly SQL Usage</a></div>
<div><a href="#" onclick="setQuery('q_1785185606');" onmouseover="showSample('q_1785185606',this);" onmouseout="cjhideqs();">Quarterly Web Hits</a></div>
</div>
</div>
<div id="hist" style="position: absolute; display: none; vertical-align: text-top;
overflow: auto; z-index: 100; padding: 2 2 2 2;" class="transparent">
</div>
<div style="">
<textarea style="display:none" id="q_377384944">-- Find unique objects in an RA/Dec box.
-- PhotoPrimary is a view which selects only unique objects.
-- The full list of good detections including duplicates is in PhotoObj
-- A basic SELECT-FROM-WHERE query.
SELECT TOP 100 objID, -- Get the unique object ID,
field, ra, dec -- the field number, and coordinates
FROM PhotoPrimary -- From the photometric data
WHERE
ra > 185. and ra < 185.1 and dec > 15. and dec < 15.1 </textarea><textarea style="display:none" id="q_1917342500">-- Galaxies meeting two simple criteria.
-- Find all galaxies brighter than r magnitude 22, where the local
-- extinction is > 0.175. This is a simple query that uses a WHERE clause,
-- but now two conditions that must be met simultaneously.
SELECT TOP 10 objID
FROM Galaxy
WHERE
r < 22 -- r IS NOT deredenned
and extinction_r > 0.175 -- extinction more than 0.175
</textarea><textarea style="display:none" id="q_199934847">-- Find specific types of quasars using spectroscopy.
-- The easiest way to find quasars is by finding objects whose spectra have
-- been classified as quasars. This sample query searches the SpecObj
-- table for the IDs and redshifts of objects with the class column equal to 'QSO'
SELECT TOP 100 specObjID, z
FROM SpecObj
WHERE class = 'QSO' AND zWarning = 0
</textarea><textarea style="display:none" id="q_1794636122">-- Using the BETWEEN syntax.
-- Find all galaxies in a certain area of the sky that also meet other
-- criteria in their measured parameters. This query intriduces the
-- BETWEEN construct to specify a range of values.
SELECT TOP 100 objID, ra, dec, cModelMag_g
FROM Galaxy
WHERE ra BETWEEN 178 AND 180
AND dec < 0
AND cModelMag_g BETWEEN 18 AND 19
</textarea><textarea style="display:none" id="q_2053263464">-- Using spatial unit vectors for coordinate cuts.
-- Find galaxies in a given area of the sky, using a coordinate cut
-- in the unit vector cx,cy,cz that corresponds to a specific RA range.
-- Another simple query that uses math in the WHERE clause.
--
-- NOTE: This query must be run in batch mode, i.e. using the Submit button
-- because it takes too long to execute in Quick mode.
SELECT TOP 100 colc_g, colc_r
FROM Galaxy
WHERE
(-0.466 * cx + 0.689 * cy>=0)
and (-0.385 * cx - 0.173 * cy <0)
</textarea><textarea style="display:none" id="q_610026851">-- Find CVs using colors.
-- Search for Cataclysmic Variables and pre-CVs with White Dwarfs and
-- very late secondaries. Just uses some simple color cuts from Paula Szkody.
-- Another simple query that uses math in the WHERE clause
SELECT TOP 100 run,
camCol,
rerun,
field,
objID,
u, g, r, i, z,
ra, dec -- Just get some basic quantities
FROM PhotoPrimary -- From all primary detections, regardless of class
WHERE u - g < 0.4
and g - r < 0.7
and r - i > 0.4
and i - z > 0.4 -- that meet the color criteria
</textarea><textarea style="display:none" id="q_347053935">-- Getting a subsample of the data.
--
-- Uses the integer short object id (obj) - which is the least significant bits
-- of the long objID - and the '%' operator (remainder) to get every 1000th
-- object.
-- NOTE: THIS IS NOT A TRULY RANDOM SAMPLE!
SELECT TOP 100 u, g, r, i, z
FROM Galaxy with (nolock)
WHERE (objID%1000) = 1
AND (r between 18 and 21)
</textarea><textarea style="display:none" id="q_1503241840">-- Low-z QSO candidates using color cuts.
-- from Gordon Richards.
-- Also a simple query with a long WHERE clause.
SELECT TOP 1000 g, run, rerun, camcol, field, objID
FROM
Galaxy
WHERE (
(g <= 22) and
(u-g >= -0.27) and (u-g < 0.71) and
(g-r >= -0.24) and (g-r < 0.35) and
(r-i >= -0.27) and (r-i < 0.57) and
(i-z >= -0.35) and (i-z < 0.70)
)</textarea><textarea style="display:none" id="q_1093157909">-- Get object velocities and errors.
-- This is also a simple query that uses a WHERE clause.
-- However, now we perform a more complex mathematical operation.
SELECT TOP 10
run, -- get a bunch of quantities
camCol,
field,
objID,
rowC, colC, rowV, colV, rowVErr, colVErr,
flags,
psfMag_u, psfMag_g, psfMag_r, psfMag_i, psfMag_z,
psfMagErr_u, psfMagErr_g, psfMagErr_r, psfMagErr_i, psfMagErr_z
FROM PhotoPrimary
WHERE ((rowv * rowv) / (rowvErr * rowvErr) +
(colv * colv) / (colvErr * colvErr) > 4)
-- where the velocities are reliable
</textarea><textarea style="display:none" id="q_1182730545">-- Finding galaxies by their emission lines:
--
-- SDSS-III handles searches by spectral lines differently than previous
-- releases. In addition, spectral lines for galaxies and stars are
-- identified through different processes. See the "Spectra of Red
-- Stars" sample query for an example of using stellar spectra.
--
-- Spectral lines for galaxies are calculated using the MPA-JHU
-- spectroscopic reanalysis (Tremonti et al. 2004; Brinchmann et al. 2004)
-- and are stored in the galSpecLine table. For more on how spectral lines
-- of galaxies are found, see the Galspec page of the sdss3.org website.
--
-- This query selects galaxy spectra with high internal reddening,
-- as measured by the standard Balmer decrement technique. It
-- makes use of the galSpec tables for the measurements of
-- galaxy lines. In this case we use galSpecLine, which has
-- emission line measurements.
SELECT
s.plate, s.fiberid, s.mjd, s.z, s.zwarning,
g.h_beta_flux, g.h_beta_flux_err,
g.h_alpha_flux, g.h_alpha_flux_err
FROM GalSpecLine AS g
JOIN dbo.SpecObj AS s ON s.specobjid = g.specobjid
WHERE
h_alpha_flux > h_alpha_flux_err*5
AND h_beta_flux > h_beta_flux_err*5
AND h_beta_flux_err > 0
AND h_alpha_flux > 10.*h_beta_flux
AND s.class = 'GALAXY'
AND s.zwarning = 0
</textarea><textarea style="display:none" id="q_1884957360">-- Moving objects consistent with an asteroid.
-- Also a simple query, but we introduce the 'as' syntax, which allows us to
-- name derived quantities in the result file.
--
-- NOTE: Since asteroids are rare objects in the SDSS data, this query will
-- take a long time to run without the "TOP 10" and should be executed
-- in batch mode (with the Submit button).
SELECT TOP 10
objID,
sqrt( power(rowv,2) + power(colv, 2) ) as velocity
FROM PhotoObj
WHERE
(power(rowv,2) + power(colv, 2)) between 50 and 1000
</textarea><textarea style="display:none" id="q_1314337809">-- Find quasars in imaging data.
-- as specified by Xiaohui Fan et.al.
-- A rather straightforward query, just with many conditions.
SELECT TOP 100 run,
camCol,
rerun,
field,
objID,
u, g, r, i, z,
ra, dec
FROM Star -- or Galaxy
WHERE ( u - g > 2.0 or u > 22.3 )
and ( i < 19 )
and ( i > 0 )
and ( g - r > 1.0 )
and ( r - i <
(0.08 + 0.42 * (g - r - 0.96) )
or g - r > 2.26 )
and ( i - z < 0.25 )
</textarea><textarea style="display:none" id="q_453086348">-- Using object counting and logic in a query.
-- Find all objects similar to the colors of a quasar at 5.5<redshift<6.5.
-- An area restriction is added so the query will run in the Quick queue.
SELECT count(*) as 'total',
sum( case when (Type=3) then 1 else 0 end) as 'Galaxies',
sum( case when (Type=6) then 1 else 0 end) as 'Stars',
sum( case when (Type not in (3,6)) then 1 else 0 end) as 'Other'
FROM PhotoPrimary -- for each object
WHERE
(ra between 180 and 190) and (dec between -5 and 5)
and (( u - g > 2.0) or (u > 22.3) ) -- apply the quasar color cut.
and ( i between 0 and 19 )
and ( g - r > 1.0 )
and ( (r - i < 0.08 + 0.42 * (g - r - 0.96)) or (g - r > 2.26 ) )
and ( i - z < 0.25 )
</textarea><textarea style="display:none" id="q_704206862">-- Find galaxies that are blended with a star.
-- Output the deblended galaxy magnitudes.
-- This query introduces the use of multiple tables or views. You can assign
-- nicknames to tables as in the FROM clause below. Since you are using
-- multiple tables, you must specify which table each quantity in the SELECT
-- clause comes from. The query illustrates the JOIN syntax between
-- the two tables, which requires that a common quantity that is present in
-- both tables be equal, in this case their common parent object.
SELECT top 1000 G.ObjID, G.u, G.g, G.r, G.i, G.z
FROM Galaxy G -- compare Galaxy and Star
JOIN Star S ON G.parentID = S.parentID -- using the same parent
WHERE
G.parentID > 0 -- if the galaxy has a "parent", this object was deblended
</textarea><textarea style="display:none" id="q_689961383">-- Stars selected using Field criteria.
-- Give me the PSF colors of all stars brighter than g=20 that have PSP_STATUS = 2.
-- Another simple multi-table query.
SELECT TOP 1000
s.psfMag_g, -- or whatever you want from each object
s.run,
s.camCol,
s.rerun,
s.field
FROM Star s
JOIN Field f ON s.fieldID = f.fieldID
WHERE
s.psfMag_g < 20
and f.pspStatus = 2
</textarea><textarea style="display:none" id="q_410365955">-- Objects selected by cuts on three tables.
-- Find the parameters for all objects in a selected field with
-- desired PSF width and range of columns.
-- Now we are using three tables, but it is still a simple query.
SELECT TOP 1000
f.run,
f.rerun,
f.camCol,
f.field,
p.objID,
p.ra,
p.dec,
p.Rowc,
p.Colc,
p.u,
p.modelMagErr_u ,
p.g,
p.modelMagErr_g,
p.r,
p.modelMagErr_r,
p.petroMag_r - p.extinction_r,
p.petroMagErr_r,
p.i,
p.modelMagErr_i,
p.z,
f.psfWidth_r,
r.stripe,
r.strip
FROM
photoObj p
JOIN field f ON f.fieldid = p.fieldid
JOIN run r ON r.run=f.run
WHERE
f.psfWidth_r > 1.2
and p.colc > 400.0
</textarea><textarea style="display:none" id="q_1684523170">-- Find all objects within 30 arcseconds of one another
-- that have very similar colors: that is where the color ratios
-- u-g, g-r, r-I are less than 0.05m. This query introduces the
-- Neighbors table, which is a pre-computed list of the nearest
-- neighbors of each object within 30 arcseconds.
SELECT TOP 10 P.ObjID as objid1, L.ObjID as objid2, N.distance
FROM PhotoPrimary P -- P is the primary object
JOIN Neighbors N ON P.ObjID = N.ObjID -- N is the neighbor link
JOIN PhotoPrimary L ON L.ObjID = N.NeighborObjID -- L is the lens candidate of P
WHERE
P.ObjID < L. ObjID -- avoid duplicates
and abs((P.u-P.g)-(L.u-L.g))<0.05 -- L and P have similar spectra
and abs((P.g-P.r)-(L.g-L.r))<0.05
and abs((P.r-P.i)-(L.r-L.i))<0.05
and abs((P.i-P.z)-(L.i-L.z))<0.05
</textarea><textarea style="display:none" id="q_1823934513">-- Find stars with multiple measurements with magnitude variations >0.1.
-- Note that this runs very slowly unless explicit workarounds are included
-- for some SQLServer Optimizer bugs, which are NOT included here
SELECT TOP 100
S1.objID as objID1, S2.objID as ObjID2 -- select object IDs of star and its pair
FROM Star as S1, -- the primary star
photoObj as S2, -- the second observation of the star
neighbors as N -- the neighbor record
WHERE S1.objID = N.objID -- insist the stars are neighbors
and S2.objID = N.neighborObjID -- using precomputed neighbors table
and distance < 0.5/60 -- distance is 0.5 arc second or less
and S1.run != S2.run -- observations are two different runs
and S2.type = dbo.fPhotoType('Star') -- S2 is indeed a star
and S1.u between 1 and 27 -- S1 magnitudes are reasonable
and S1.g between 1 and 27
and S1.r between 1 and 27
and S1.i between 1 and 27
and S1.z between 1 and 27
and S2.u between 1 and 27 -- S2 magnitudes are reasonable.
and S2.g between 1 and 27
and S2.r between 1 and 27
and S2.i between 1 and 27
and S2.z between 1 and 27
and ( -- and one of the colors is different.
abs(S1.u-S2.u) > .1 + (abs(S1.Err_u) + abs(S2.Err_u))
or abs(S1.g-S2.g) > .1 + (abs(S1.Err_g) + abs(S2.Err_g))
or abs(S1.r-S2.r) > .1 + (abs(S1.Err_r) + abs(S2.Err_r))
or abs(S1.i-S2.i) > .1 + (abs(S1.Err_i) + abs(S2.Err_i))
or abs(S1.z-S2.z) > .1 + (abs(S1.Err_z) + abs(S2.Err_z))
)
</textarea><textarea style="display:none" id="q_348348979">-- Checking for errors using flags.
-- Another useful query is to see if the errors on moving (or
-- apparently moving) objects are correct. For example, it used to be that
-- some known QSOs were being flagged as moving objects. One way to look for
-- such objects is to compare the velocity to the error in velocity and see if
-- the "OBJECT1_MOVED" or "OBJECT2_BAD_MOVING_FIT" is set.
-- This query introduces bitwise logic for flags, and uses the 'as' syntax to
-- make the query more readable. Note that if a flag is not set, the value
-- will be zero. If you want to ensure multiple flags are not set, you can
-- either check that each individually is zero, or that their sum is zero.
-- (From Gordon Richards)
--
-- NOTE: A caveat about using functons (like fPhotoFlags) is that if your
-- query is selecting a very large number of rows (e.g. hundreds of
-- thousands or millions) then it's that many function calls, and
-- this will slow down the query execution significantly. In that
-- case, you should replace the function call with its equivalent
-- binary bitmask, e.g. if you run the query (with Quick button)
-- SELECT (dbo.fPhotoFlags('MOVED') + dbo.fPhotoFlags('BAD_MOVING_FIT'))
-- you will get the value 36507222016, which you can substitute in
-- first line of the WHERE clause below as:
-- (flags & 36507222016) > 0
-- to avoid zillions of function calls.
SELECT TOP 1000
run,
rerun,
camcol,
field,
objID,
ra, dec,
rowv, colv,
rowvErr, colvErr,
i,
(flags & dbo.fPhotoFlags('MOVED')) as MOVED,
(flags & dbo.fPhotoFlags('BAD_MOVING_FIT')) as BAD_MOVING_FIT
FROM Galaxy
WHERE
(flags & (dbo.fPhotoFlags('MOVED') + dbo.fPhotoFlags('BAD_MOVING_FIT'))) > 0
and (rowv * rowv + colv * colv) >=
(rowvErr * rowvErr + colvErr * colvErr)
</textarea><textarea style="display:none" id="q_569145814">-- Elliptical galaxies based on model fits.
-- Find all galaxies with a deVaucouleours profile and the
-- photometric colors consistent with an elliptical galaxy.
-- This query has many conditions, and also shows more of the
-- bitwise logic necessary for dealing with flags.
SELECT TOP 100 ObjID
FROM Galaxy as G
WHERE
G.lnlDev_r > G.lnlExp_r + 0.1
-- the likelihood of the deVaucouleours profile fit is 10% greater than the likelihood of the exponential fit
and G.lnlExp_r > -999
-- and the likelihoods are actually meaningful
and (G.flags & (dbo.fPhotoFlags('BINNED1') + dbo.fPhotoFlags('BINNED2') + dbo.fPhotoFlags('BINNED4'))) > 0
--and it is detected from at least one of the binned images ???
and (G.flags & ( dbo.fPhotoFlags('BLENDED') + dbo.fPhotoFlags('NODEBLEND') + dbo.fPhotoFlags('CHILD'))) != dbo.fPhotoFlags('BLENDED')
--and, if it is blended, it is either a child or not deblended further ??
and (G.flags & (dbo.fPhotoFlags('EDGE') + dbo.fPhotoFlags('SATURATED'))) = 0
-- and it is not near a ccd edge or saturated, where measurements may be bad
and G.petroMag_i > 17.5
-- and it is fainter than 17.5 in i-band
and (G.petroMag_r > 15.5 or G.petror50_r > 2)
and (G.petroMag_r > 0 and G.g > 0 and G.r > 0 and G.i > 0)
and ( (G.petroMag_r - G.extinction_r) < 19.2
and (G.petroMag_r - G.extinction_r <
(13.1 + (7/3)*(G.g - G.r) + 4 *(G.r - G.i) - 4 * 0.18 ) )
and ( (G.r - G.i - (G.g - G.r)/4 - 0.18) < 0.2 )
and ( (G.r - G.i - (G.g - G.r)/4 - 0.18) > -0.2 ) )
or ( (G.petroMag_r - G.extinction_r < 19.5)
and ( (G.r - G.i - (G.g - G.r)/4 - 0.18) >
(0.45 - 4*(G.g - G.r) ) )
and ( (G.g - G.r) > (1.35 + 0.25 *(G.r - G.i) ) ) )
-- and many constraints on colors and mags are met to make it have
-- elliptical-type colors.
</textarea><textarea style="display:none" id="q_1687216546">-- Galaxies with bluer centers.
-- by Michael Strauss. For all galaxies
-- with r_Petro < 18, not saturated, not bright, and not edge, give me those
-- with centers appreciably bluer than their outer parts, i.e., define the
-- center color as: u_psf - g_psf and define the outer color as: u_model -
-- g_model; give me all objs which have (u_model - g_model) - (u_psf - g_psf)
-- < -0.4
-- Another flags-based query.
SELECT TOP 1000
colc_u, colc_g, objID
FROM Galaxy
WHERE
( Flags & (dbo.fPhotoFlags('SATURATED') +
dbo.fPhotoFlags('BRIGHT') +
dbo.fPhotoFlags('EDGE')) ) = 0
and petrorad_r < 18
and ((colc_u - colc_g) - (psfMag_u - psfMag_g)) < -0.4</textarea><textarea style="display:none" id="q_113893222">-- Diameter-limited sample of galaxies
-- from James Annis.
-- Another query that makes extensive use of photo flags to get a sample
-- of galaxies within a size range as specified by their i-band Petrosian
-- radius.
SELECT TOP 100
run,
camCol,
rerun,
field,
objID,
ra,
dec
FROM Galaxy
WHERE ( flags & (dbo.fPhotoFlags('BINNED1')
+ dbo.fPhotoFlags('BINNED2')
+ dbo.fPhotoFlags('BINNED4')) ) > 0
and ( flags & (dbo.fPhotoFlags('BLENDED')
+ dbo.fPhotoFlags('NODEBLEND')
+ dbo.fPhotoFlags('CHILD')) ) != dbo.fPhotoFlags('BLENDED')
and ( ( (flags & dbo.fPhotoFlags('NOPETRO') = 0)
and petrorad_i > 15)
or ( (flags & dbo.fPhotoFlags('NOPETRO') > 0)
and petrorad_i > 7.5)
or ( (flags & dbo.fPhotoFlags('TOO_LARGE') > 0)
and petrorad_i > 2.5)
or
( (flags & dbo.fPhotoFlags('SATURATED') = 0)
and petrorad_i > 17.5) )
</textarea><textarea style="display:none" id="q_1471444940">-- Extremely red galaxies.
-- from James Annis.
-- Similar to the diameter limited sample query but selects galaxies that
-- are red (i-z color greater than a certain threshold).
SELECT TOP 1000
g.run,
g.camCol,
g.rerun,
g.field,
g.objID,
g.ra, g.dec
FROM Field f, Galaxy g
WHERE
g.fieldID = f.fieldID
and ( g.flags & (dbo.fPhotoFlags('BINNED1')
+ dbo.fPhotoFlags('BINNED2')
+ dbo.fPhotoFlags('BINNED4')) ) > 0
and ( g.flags & (dbo.fPhotoFlags('BLENDED')
+ dbo.fPhotoFlags('NODEBLEND')
+ dbo.fPhotoFlags('CHILD')) ) != dbo.fPhotoFlags('BLENDED')
and ( g.flags & (dbo.fPhotoFlags('COSMIC_RAY')
+ dbo.fPhotoFlags('INTERP')) ) = 0
and f.psfWidth_r < 1.5
and (g.i - g.z > 1.0 )
</textarea><textarea style="display:none" id="q_1092529461">-- A version of the LRG sample.
-- by James Annis.
-- Another query with many conditions and flag tests that selects Luminous
-- Red Galaxies (LRGs).
SELECT TOP 100
run,
camCol,
rerun,
field,
objID,
ra,
dec
FROM Galaxy
WHERE ( ( flags & (dbo.fPhotoFlags('BINNED1')
+ dbo.fPhotoFlags('BINNED2')
+ dbo.fPhotoFlags('BINNED4')) ) > 0
and ( flags & (dbo.fPhotoFlags('BLENDED')
+ dbo.fPhotoFlags('NODEBLEND')
+ dbo.fPhotoFlags('CHILD')) ) != dbo.fPhotoFlags('BLENDED')
and ( flags & (dbo.fPhotoFlags('EDGE')
+ dbo.fPhotoFlags('SATURATED')) ) = 0
and petroMag_i > 17.5
and (petroMag_r > 15.5 or petror50_r > 2)
and (petroMag_r > 0 and g > 0 and r > 0 and i > 0)
and ( (petroMag_r-extinction_r) < 19.2
and (petroMag_r - extinction_r <
(13.1 + (7/3) * (dered_g - dered_r) + 4 * (dered_r - dered_i) - 4 * 0.18) )
and ( (dered_r - dered_i - (dered_g - dered_r)/4 - 0.18) < 0.2)
and ( (dered_r - dered_i - (dered_g - dered_r)/4 - 0.18) > -0.2)
--dered_ quantities already include extinction
and ( (petroMag_r - extinction_r +
2.5 * LOG10(2 * 3.1415 * petror50_r * petror50_r)) < 24.2) )
or ( (petroMag_r - extinction_r < 19.5)
and ( (dered_r - dered_i - (dered_g - dered_r)/4 - 0.18) > (0.45 - 4 * (dered_g - dered_r)) )
and ( (dered_g - dered_r) > (1.35 + 0.25 * (dered_r - dered_i)) ) )
and ( (petroMag_r - extinction_r +
2.5 * LOG10(2 * 3.1415 * petror50_r * petror50_r) ) < 23.3 ) )
</textarea><textarea style="display:none" id="q_1476423508">-- Spectra of Red Stars
--
-- SDSS-III handles searches by spectral lines differently than previous
-- releases. In addition, spectral lines for galaxies and stars are
-- identified through different processes. See the "Galaxies with
-- Emission Lines" sample query for an example of using galaxy spectra.
--
-- Spectral lines for stars are calculated using the SEGUE Stellar Parameter
-- Pipeline (SSPP; Lee et al. 2008) and are stored in the sppLines
-- table. For more on how spectral lines of stars are found, see
-- the SSPP page of the sdss3.org website.
-- This query selects red stars (spectral type K), with large
-- CaII triplet eq widths, with low errors on the CaII triplet
-- equivalent widths.
SELECT
sl.plate,sl.mjd,sl.fiber,
sl.caIIKside,sl.caIIKerr,sl.caIIKmask,
sp.fehadop,sp.fehadopunc,sp.fehadopn,
sp.loggadopn,sp.loggadopunc
FROM sppLines AS sl
JOIN sppParams AS sp ON sl.specobjid = sp.specobjid
WHERE
fehadop < -3.5
AND fehadopunc between 0.01
and 0.5 and fehadopn > 3
</textarea><textarea style="display:none" id="q_1964088379">-- Galaxy counts on HTM grid.
--
-- Create a count of galaxies for each of the Hierarchical Triangular Mesh (HTM) triangles.
-- Galaxies should satisfy a certain color cut like 0.7u-0.5g-0.2i<1.25 && r<21.75, output
-- it in a form adequate for visualization.
SELECT (htmID / power(2,24)) as htm_8 ,
-- group by 8-deep HTMID (rshift HTM by 12)
avg(ra) as ra,
avg(dec) as [dec],
count(*) as pop -- return center point and count for display
FROM Galaxy -- only look at galaxies
WHERE
-- RA/dec cut added to make query run in Quick mode
(ra between 180 and 181 and dec between -1 and 1) and
(0.7*u - 0.5*g - 0.2*i) < 1.25 -- meeting this color cut
and r < 21.75 -- brighter than 21.75 magnitude in red band.
group by (htmID /power(2,24)) -- group into 8-deep HTM buckets.
</textarea><textarea style="display:none" id="q_1609807292">-- Binary Stars Colors.
--
-- Find binary stars with specific colors.
-- At least one of them should have the colors (meets Paul Szkody's color cut) of a white dwarf.
SELECT TOP 100 s1.objID as s1, s2.objID as s2
FROM Star S1 -- S1 is the white dwarf
JOIN Neighbors N ON S1.objID = N. objID -- N is the precomputed neighbors link
JOIN Star S2 ON S2.objID = N.NeighborObjID -- S2 is the second star
WHERE
N.neighborType = dbo.fPhotoType('Star') -- and S2 is a star
and N.distance < .05 -- the 3 arcsecond test
and ((S1.u - S1.g) < 0.4 ) -- and S1 meets the color cut for
and (S1.g - S1.r) < 0.7 -- white dwarfs.
and (S1.r - S1.i) > 0.4
and (S1.i - S1.z) > 0.4
</textarea><textarea style="display:none" id="q_949416951">-- Galaxies unsaturated near (given) coordinates.
--
-- Find galaxies without saturated pixels within 1' of a given point.
-- ra=185.0, dec=-0.5. This query uses a function fGetNearbyObjEq,
-- which takes 3 arguments (ra,dec, distance in arcmin); this function uses
-- the Neighbors table. The Neighbors table and the Galaxy table have in
-- common the objID, so we have to select objects from both where the objIDs
-- are the same. The output of the function is a table with the Galaxy Object
-- ID and distance in arcmin from the input. This query introduces the use of
-- a JOIN to combine table contents. Also, we use the 'ORDER BY' syntax,
-- which will sort the output.
SELECT TOP 100 G.objID, GN.distance
FROM Galaxy AS G
JOIN dbo.fGetNearbyObjEq(185.,-0.5, 1) AS GN -- this function outputs a table, so we have to do a join
ON G.objID = GN.objID -- get objects from temporary neighbors table GN with desired ObjID
WHERE
(G.flags & dbo.fPhotoFlags('saturated')) = 0 -- and the object is not saturated. f.PhotoFlags is a function that interprets the flag bits.
ORDER BY distance -- sort these by distance
</textarea><textarea style="display:none" id="q_1820036051">-- Search near BCG galaxies.
--
-- For each galaxy in the BCG data set (brightest cluster galaxy),
-- in 160<right ascension<170, -25<declination<35 count the number of
-- galaxies within 30" of it that have a photoz within 0.05
-- of that galaxy.
-- This query has a very complex WHERE clause.
SELECT TOP 1000 G.objID, COUNT(N.NeighborObjID) AS pop
FROM Galaxy AS G -- first gravitational lens candidate
JOIN Neighbors AS N ON G.objID = N.objID -- precomputed list of neighbors
JOIN Galaxy AS U ON U.objID = N.neighborObjID -- a neighbor galaxy of G
JOIN photoZ AS Gpz ON G.objID = Gpz.objID -- photoZ of G.
JOIN photoZ AS Npz ON U.objID = Npz.objID -- neighbor photoZ
WHERE
G.ra BETWEEN 160 AND 170
AND G.dec BETWEEN -5 AND 5
AND N.objID < N.neighborObjID -- 30 arcseconds of one another.
AND ABS(Gpz.Z - Npz.Z) < 0.05 -- restrict the photoZ differences
AND (G.flags & (dbo.fPhotoFlags('BINNED1') + dbo.fPhotoFlags('BINNED2') + dbo.fPhotoFlags('BINNED4'))) > 0
--and it is detected from at least one of the binned images
AND (G.flags & ( dbo.fPhotoFlags('BLENDED') + dbo.fPhotoFlags('NODEBLEND') + dbo.fPhotoFlags('CHILD'))) != dbo.fPhotoFlags('BLENDED')
--and, if it is blended, it is either a child or not deblended further ??
AND (G.flags & (dbo.fPhotoFlags('EDGE') + dbo.fPhotoFlags('SATURATED'))) = 0
-- and it is not near a ccd edge or saturated, where measurements may be bad
-- and apply color cut for a BCG courtesy of James Annis of Fermilab
AND G.petroMag_i > 17.5
AND (G.petroMag_r > 15.5 or G.petror50_r > 2)
AND (G.petroMag_r < 30 AND G.g < 30 AND G.r < 30 AND G.i < 30)
AND (G.r < 19.2
AND ( 1=1 or -- huh?
(G.r < (13.1 + (7/3)*(G.g - G.r) +
-- deRed_r < 13.1 + 0.7 / 0.3 * deRed_gr
4 *(G.r - G.i - 0.18 ))
-- 1.2 / 0.3 * deRed_ri
AND (( G.r - G.i - (G.g - G.r)/4 - 0.18) BETWEEN -0.2 AND 0.2 )
AND ((G.r +
-- petSB - deRed_r + 2.5 log10(2Pi*petror50^2)
2.5 * LOG( 2 * 3.1415 * G.petror50_r * G.petror50_r )) < 24.2 )
)
or
( (G.r < 19.5 )
AND (( G.r - G.i -(G.g - G.r)/4 -.18) >
-- - deRed_gr/4 - 0.18
-- cperp = deRed_ri
(0.45 - 4*( G.g - G.r)))
-- 0.45 - deRed_gr/0.25
AND ((G.g - G.r) > ( 1.35 + 0.25 *(G.r - G.i)))
AND ((G.r +
-- petSB - deRed_r + 2.5 log10(2Pi*petror50^2)
2.5 * LOG( 2 * 3.1415 * G.petror50_r * G.petror50_r )) < 23.3 )
)) )
GROUP BY G.objID
</textarea><textarea style="display:none" id="q_2086102066">-- The detectionIndex table contains all detections of a given physical object,
-- which is uniquely identified by the "thingid". In order to extract photometry,
-- you need a join with the PhotoObjAll table, using the objid.
-- There is also a flag field called isPrimary, which is 1 for the object that
-- is found on a primary polygon/field, all the other detections have 0 in this field.
-- Here is a compound query to find all time series around a certain object with a thingid= 97423000
SELECT
LTRIM(STR(mjd_r,20,2)) AS MJD,
dbo.fSDSS(p.objId) AS ID,
modelMag_g, modelMagErr_g,
modelMag_r, modelMagErr_r,
modelMag_i, modelMagErr_i, p.ra, p.dec
INTO #list
FROM detectionindex d
JOIN PhotoObjAll p ON d.objid=p.objid
JOIN Field f ON p.fieldid=f.fieldid
WHERE d.thingid=97423000
ORDER BY 1
GO
--
-- Now find objects near each of the detections
--
SELECT a.*, b.*
FROM #list a
CROSS APPLY dbo.fGetNearbyObjEq(a.ra, a.dec, 0.1) b
</textarea>
<textarea style="display:none" id="q_1342567403">-- Here's a query that looks at average query time by month, for all queries that took longer then 10 minutes.
select
(
convert(varchar, datepart(year, timestart))+'_'+
right('00'+convert(varchar,datepart(month, timestart)),2)
) as yymm,
avg (
datepart(hour, (timeend - timestart)) * 360 +
datepart(minute, (timeend - timestart)) * 60 +
datepart(second, (timeend - timestart))
) as avgseconds
from jobs
where
timeend - timestart > 0
and timeend is not null
and (
datepart(hour, (timeend - timestart)) * 60 +
datepart(minute, (timeend - timestart))
) >= 10
and taskname not like '%__SYSTEM__%'
and estimate > 1
group by
convert(varchar, datepart(year, timestart))+'_'+
right('00'+convert(varchar,datepart(month, timestart)),2)
order by
convert(varchar, datepart(year, timestart))+'_'+
right('00'+convert(varchar,datepart(month, timestart)),2)
</textarea><textarea style="display:none" id="q_1185292591">-- Accounts created, monthly. This is not cumulative.
select
(
convert(varchar, datepart(year, timecreated))+'_'+
right('00'+convert(varchar,datepart(month, timecreated)),2)
) as yymm,
count(*) as ucnt
from users
group by
convert(varchar, datepart(year, timecreated))+'_'+
right('00'+convert(varchar,datepart(month, timecreated)),2)
order by
convert(varchar, datepart(year, timecreated))+'_'+
right('00'+convert(varchar,datepart(month, timecreated)),2)</textarea>
<textarea style="display:none" id="q_2127032053">-- Basic_SELECT_FROM_WHERE
-- Find objects in a particular field.
SELECT objID,
field, ra, dec -- Get the unique object ID, field number, and coords
FROM PhotoObj -- From the photometric data
WHERE fieldID = 587722951961673728 -- that is in a specific field
</textarea><textarea style="display:none" id="q_1822251911">-- Galaxies meeting two simple criteria.
-- Find all galaxies brighter than r magnitude 17, where the local
-- extinction is > 0.275. This is a simple query that uses a WHERE clause,
-- but now two conditions that must be met simultaneously.
--
-- Finds 6604 galaxies in under 10 mins on DR2, but beware that increasing
-- the limiting r magnitude will significantly add to the execution time.
SELECT objID
FROM Galaxy
WHERE
r < 17 -- r IS NOT deredenned
and extinction_r > 0.275 -- extinction more than 0.175
</textarea><textarea style="display:none" id="q_2112964880">-- Find all objects with unclassified spectra.
-- A simple SELECT-FROM-WHERE query, using a function
--
-- On DR2, returns 3109 rows in 20 sec.
SELECT specObjID
FROM SpecObj
WHERE SpecClass = dbo.fSpecClass('UNKNOWN')</textarea><textarea style="display:none" id="q_1876103269">-- Galaxies meeting multiple simple criteria.
-- Find all galaxies with blue surface brightness between 23 and 25
-- mag per square arcseconds, and -10 < supergalactic latitude (sgb) < 10, and
-- declination less than zero. Currently, we have to live with ra/dec until we
-- get galactic coordinates. To calculate surface brightness per sq. arcsec,
-- we use (g + rho), where g is the blue magnitude, and rho= 5*log(r). This
-- query now has three requirements, one involving simple math.
--
-- On DR2, returns 61090 rows in 330 sec.
SELECT objID
FROM Galaxy
WHERE ra between 178 and 180
and dec < 0
-- and (g+rho) between 23 and 25
and g between (23-rho) and (25-rho)
-- g is the blue magnitude, and rho= 5*log(Petro radius)</textarea><textarea style="display:none" id="q_1604660031">-- Using spatial unit vectors for coordinate cuts.
-- Find galaxies in a given area of the sky, using a coordinate cut
-- in the unit vector cx,cy,cz that corresponds to a specific RA range.
-- Another simple query that uses math in the WHERE clause.
--
-- Finds 100 galaxies in 230 sec on DR2, but this is a very slow way to do
-- coordinate cuts. Using RA/dec is *much* faster due to indexing.
--
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT TOP 100 colc_g, colc_r
FROM Galaxy
WHERE
(-0.466 * cx + 0.689 * cy>=0)
and (-0.385 * cx - 0.173 * cy <0)
</textarea><textarea style="display:none" id="q_1209894154">-- Find CVs using colors.
-- Search for Cataclysmic Variables and pre-CVs with White Dwarfs and
-- very late secondaries. Just uses some simple color cuts from Paula Szkody.
-- Another simple query that uses math in the WHERE clause
--
-- Finishes in 72 sec on DR2.
SELECT TOP 10000 run,
camCol,
rerun,
field,
objID,
u, g, r, i, z,
ra, dec -- Just get some basic quantities
FROM PhotoPrimary -- From all primary detections, regardless of class
WHERE u - g < 0.4
and g - r < 0.7
and r - i > 0.4
and i - z > 0.4 -- that meet the color criteria
</textarea><textarea style="display:none" id="q_1732295176">-- Getting a subsample of the data.
-- Uses the integer short object id (obj) and the '%' syntax (like awk)
-- to get every 1000th object. THIS IS NOT A TRULY RANDOM SUBSET!
--
-- Returns 11367 objects in DR2 (in about 10-15mins).
SELECT u, g, r, i, z
FROM Galaxy with (nolock)
WHERE (objID%1000) = 1
AND (r between 18 and 21)
</textarea><textarea style="display:none" id="q_2122410695">-- Low-z QSO candidates using color cuts.
-- from Gordon Richards.
-- Also a simple query with a long WHERE clause.
SELECT TOP 1000 g, run, rerun, camcol, field, objID
FROM
Galaxy
WHERE (
(g <= 22) and
(u-g >= -0.27) and (u-g < 0.71) and
(g-r >= -0.24) and (g-r < 0.35) and
(r-i >= -0.27) and (r-i < 0.57) and
(i-z >= -0.35) and (i-z < 0.70)
)</textarea><textarea style="display:none" id="q_162421342">-- Get object velocities and errors.
-- This is also a simple query that uses a WHERE clause.
-- However, now we perform a more complex mathematical operation.
SELECT TOP 1000
run, -- get a bunch of quantities
camCol,
field,
objID,
rowC, colC, rowV, colV, rowVErr, colVErr,
flags,
psfMag_u, psfMag_g, psfMag_r, psfMag_i, psfMag_z,
psfMagErr_u, psfMagErr_g, psfMagErr_r, psfMagErr_i, psfMagErr_z
FROM PhotoPrimary
WHERE ((rowv * rowv) / (rowvErr * rowvErr) +
(colv * colv) / (colvErr * colvErr) > 4)
-- where the velocities are reliable
</textarea><textarea style="display:none" id="q_1947188265">-- Using the BETWEEN syntax.
-- Find galaxies with an isophotal surface brightness (SB) larger
-- than 24 in the red band, and with an ellipticity > 0.5, and with the major
-- axis of the ellipse having a declination between 30" and 60" arc seconds.
-- This is also a simple query that uses a WHERE clause with three conditions
-- that must be met. We introduce the syntax 'BETWEEN' to do a range search.
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT TOP 100 ObjID
FROM Galaxy
WHERE r < 24 - rho
-- surface brightness brighter than 24 mag. per sq. arcsec in the red
-- Note that isolating r (indexed) on one side helps this run faster
and isoA_r between 30 and 60
-- major axis between 30" and 60"
and (power(q_r,2) + power(u_r,2)) > 0.25
-- square of ellipticity is > 0.5 squared. The SQL term 'power' is used for exponentiation.</textarea><textarea style="display:none" id="q_1076082999">-- Moving objects consistent with an asteroid.
-- Also a simple query, but we introduce the 'as' syntax, which allows us to
-- name derived quantities in the result file.
--
--This Sample Query will not work for SDSS3 contexts
SELECT TOP 10
objID,
sqrt( power(rowv,2) + power(colv, 2) ) as velocity
FROM PhotoObj
WHERE
(power(rowv,2) + power(colv, 2)) between 50 and 1000
</textarea><textarea style="display:none" id="q_362452986">-- Find quasars in imaging data.
-- as specified by Xiaohui Fan et.al.
-- A rather straightforward query, just with many conditions.
SELECT TOP 1000 run,
camCol,
rerun,
field,
objID,
u, g, r, i, z,
ra, dec
FROM Star -- or Galaxy
WHERE ( u - g > 2.0 or u > 22.3 )
and ( i < 19 )
and ( i > 0 )
and ( g - r > 1.0 )
and ( r - i <
(0.08 + 0.42 * (g - r - 0.96) )
or g - r > 2.26 )
and ( i - z < 0.25 )
</textarea><textarea style="display:none" id="q_2140829941">-- Using object counting and logic in a query.
-- Find all objects similar to the colors of a quasar at 5.5<redshift<6.5.
SELECT count(*) as 'total',
sum( case when (Type=3) then 1 else 0 end) as 'Galaxies',
sum( case when (Type=6) then 1 else 0 end) as 'Stars',
sum( case when (Type not in (3,6)) then 1 else 0 end) as 'Other'
FROM PhotoPrimary -- for each object
WHERE (( u - g > 2.0) or (u > 22.3) ) -- apply the quasar color cut.
and ( i between 0 and 19 )
and ( g - r > 1.0 )
and ( (r - i < 0.08 + 0.42 * (g - r - 0.96)) or (g - r > 2.26 ) )
and ( i - z < 0.25 )
</textarea><textarea style="display:none" id="q_1307734809">-- Find galaxies that are blended with a star.
-- Output the deblended galaxy magnitudes.
-- This query introduces the use of multiple tables or views. You can assign
-- nicknames to tables as in the FROM clause below. Since you are using
-- multiple tables, you ,ust specify which table each quantity in the SELECT
-- clause comes from. Finally, the last line in the query is the join between
-- the two tables, which is achieved by requiring that a quantity present in
-- both tables be equal.
-- NOTE: This query times out (takes too long) without the "TOP 1000".
SELECT top 1000 G.ObjID, G.u, G.g, G.r, G.i, G.z --get the ObjID and final mags
FROM Galaxy G, Star S -- use two Views, Galaxy and Star, as a convenient mechanism to compare objects
WHERE G.parentID > 0 -- galaxy has a "parent", which tells us this object was deblended
and G.parentID = S.parentID -- and the star has the same parent
</textarea><textarea style="display:none" id="q_699861840">-- Stars selected using Field criteria.
-- Give me the PSF colors of all stars brighter than g=20 that have PSP_STATUS = 2.
-- Another simple multi-table query.
SELECT TOP 1000
s.psfMag_g, -- or whatever you want from each object
s.run,
s.camCol,
s.rerun,
s.field
FROM Star s, Field f
WHERE s.fieldID = f.fieldID
and s.psfMag_g < 20
and f.pspStatus = 2</textarea><textarea style="display:none" id="q_1448724282">-- Objects selected by cuts on three tables.
-- Find the parameters for all objects in a selected field with
-- desired PSF width and range of columns.
-- Now we are using three tables, but it is still a simple query.
-- NOTE: This query times out (takes too long) without the "TOP 1000".
SELECT TOP 1000
f.run,
f.rerun,
f.camCol,
f.field,
p.objID,
p.ra,
p.dec,
p.Rowc,
p.Colc,
p.u,
p.modelMagErr_u ,
p.g,
p.modelMagErr_g,
p.r,
p.modelMagErr_r,
p.petroMag_r - p.extinction_r,
p.petroMagErr_r,
p.i,
p.modelMagErr_i,
p.z,
f.psfWidth_r
FROM
photoObj p, field f
WHERE
f.fieldid = p.fieldid
and f.psfWidth_r > 1.2
and p.colc > 400.0
</textarea><textarea style="display:none" id="q_1373505727">-- Find all objects within 30 arcseconds of one another
-- that have very similar colors: that is where the color ratios
-- u-g, g-r, r-I are less than 0.05m.
SELECT TOP 10 P.ObjID -- distinct cases
FROM PhotoPrimary P, -- P is the primary object
Neighbors N, -- N is the neighbor link
PhotoPrimary L -- L is the lens candidate of P
WHERE P.ObjID = N.ObjID -- N is a neighbor record
and L.ObjID = N.NeighborObjID -- L is a neighbor of P
and P.ObjID < L. ObjID -- avoid duplicates
and abs((P.u-P.g)-(L.u-L.g))<0.05 -- L and P have similar spectra.
and abs((P.g-P.r)-(L.g-L.r))<0.05
and abs((P.r-P.i)-(L.r-L.i))<0.05
and abs((P.i-P.z)-(L.i-L.z))<0.05
</textarea><textarea style="display:none" id="q_203899950">-- Find specific types of quasars using spectroscopy.
-- The easiest way to find quasars is by finding objects whose spectra have
-- been classified as quasars. This sample query searches the SpecObj
-- table for the IDs and redshifts of objects with the class column equal to 'QSO'
SELECT TOP 100 specObjID, z
FROM SpecObj
WHERE class = 'QSO' AND zWarning = 0
</textarea><textarea style="display:none" id="q_160825834">-- Checking for errors using flags.
-- Another useful query is to see if the errors on moving (or
-- apparently moving) objects are correct. For example, it used to be that
-- some known QSOs were being flagged as moving objects. One way to look for
-- such objects is to compare the velocity to the error in velocity and see if
-- the "OBJECT1_MOVED" or "OBJECT2_BAD_MOVING_FIT" is set.
-- This query introduces bitwise logic for flags, and uses the 'as' syntax to
-- make the query more readable. Note that if a flag is not set, the value
-- will be zero. If you want to ensure multiple flags are not set, you can
-- either check that each individually is zero, or their sum is zero.
-- (From Gordon Richards)
SELECT TOP 1000
run,
rerun,
camcol,
field,
objID,
ra, dec,
rowv, colv,
rowvErr, colvErr,
i,
(flags & dbo.fPhotoFlags('MOVED')) as MOVED,
(flags & dbo.fPhotoFlags('BAD_MOVING_FIT')) as BAD_MOVING_FIT
FROM Galaxy
WHERE
(flags & (dbo.fPhotoFlags('MOVED') + dbo.fPhotoFlags('BAD_MOVING_FIT'))) > 0
and (rowv * rowv + colv * colv) >=
(rowvErr * rowvErr + colvErr * colvErr)</textarea><textarea style="display:none" id="q_1984607857">-- Elliptical galaxies based on model fits.
-- Find all galaxies with a deVaucouleours profile and the
-- photometric colors consistent with an elliptical galaxy. NOTE THAT THE
-- NAMES and VALUES OF THE LIKELIHOODS HAVE CHANGED SINCE THE EDR; they are
-- now log likelihoods, and named accordingly (lDev is now lnlDev, etc.) to
-- indicate these are log likelihoods. This query has many conditions, and
-- also has the use of bitwise logic necessary for dealing with flags.
SELECT TOP 100 ObjID
FROM Galaxy as G
WHERE
G.lnlDev_r > G.lnlExp_r + 0.1
-- the likelihood of the deVaucouleours profile fit is 10% greater than the likelihood of the exponential fit
and G.lnlExp_r > -999
-- and the likelihoods are actually meaningful
and (G.flags & (dbo.fPhotoFlags('BINNED1') + dbo.fPhotoFlags('BINNED2') + dbo.fPhotoFlags('BINNED4'))) > 0
--and it is detected from at least one of the binned images ???
and (G.flags & ( dbo.fPhotoFlags('BLENDED') + dbo.fPhotoFlags('NODEBLEND') + dbo.fPhotoFlags('CHILD'))) != dbo.fPhotoFlags('BLENDED')
--and, if it is blended, it is either a child or not deblended further ??
and (G.flags & (dbo.fPhotoFlags('EDGE') + dbo.fPhotoFlags('SATURATED'))) = 0
-- and it is not near a ccd edge or saturated, where measurements may be bad
and G.petroMag_i > 17.5
-- and it is fainter than 17.5 in i-band
and (G.petroMag_r > 15.5 or G.petror50_r > 2)
and (G.petroMag_r > 0 and G.g > 0 and G.r > 0 and G.i > 0)
and ( (G.petroMag_r - G.extinction_r) < 19.2
and (G.petroMag_r - G.extinction_r <
(13.1 + (7/3)*(G.g - G.r) + 4 *(G.r - G.i) - 4 * 0.18 ) )
and ( (G.r - G.i - (G.g - G.r)/4 - 0.18) < 0.2 )
and ( (G.r - G.i - (G.g - G.r)/4 - 0.18) > -0.2 ) )
or ( (G.petroMag_r - G.extinction_r < 19.5)
and ( (G.r - G.i - (G.g - G.r)/4 - 0.18) >
(0.45 - 4*(G.g - G.r) ) )
and ( (G.g - G.r) > (1.35 + 0.25 *(G.r - G.i) ) ) )
-- and many constraints on colors and mags are met to make it have
-- elliptical-type colors.
</textarea><textarea style="display:none" id="q_2071057527">-- Galaxies with bluer centers.
-- by Michael Strauss. For all galaxies
-- with r_Petro < 18, not saturated, not bright, and not edge, give me those
-- with centers appreciably bluer than their outer parts, i.e., define the
-- center color as: u_psf - g_psf and define the outer color as: u_model -
-- g_model; give me all objs which have (u_model - g_model) - (u_psf - g_psf)
-- < -0.4
-- Another flags-based query.
SELECT TOP 1000
colc_u, colc_g, objID
FROM Galaxy
WHERE
( Flags & (dbo.fPhotoFlags('SATURATED') +
dbo.fPhotoFlags('BRIGHT') +
dbo.fPhotoFlags('EDGE')) ) = 0
and petrorad_r < 18
and ((colc_u - colc_g) - (psfMag_u - psfMag_g)) < -0.4</textarea><textarea style="display:none" id="q_1616963259">-- Diameter-limited sample of galaxies
-- from James Annis.
SELECT TOP 1000
run,
camCol,
rerun,
field,
objID,
ra,
dec
FROM Galaxy
WHERE ( flags & (dbo.fPhotoFlags('BINNED1')
+ dbo.fPhotoFlags('BINNED2')
+ dbo.fPhotoFlags('BINNED4')) ) > 0
and ( flags & (dbo.fPhotoFlags('BLENDED')
+ dbo.fPhotoFlags('NODEBLEND')
+ dbo.fPhotoFlags('CHILD')) ) != dbo.fPhotoFlags('BLENDED')
and ( ( (flags & dbo.fPhotoFlags('NOPETRO') = 0)
and petrorad_i > 15)
or ( (flags & dbo.fPhotoFlags('NOPETRO') > 0)
and petrorad_i > 7.5)
or ( (flags & dbo.fPhotoFlags('TOO_LARGE') > 0)
and petrorad_i > 2.5)
or
( (flags & dbo.fPhotoFlags('SATURATED') = 0)
and petrorad_i > 17.5) )
</textarea><textarea style="display:none" id="q_1224142175">-- Extremely red galaxies.
-- from James Annis.
-- Similar to the diameter limited sample query.
SELECT TOP 1000
g.run,
g.camCol,
g.rerun,
g.field,
g.objID,
g.ra, g.dec
FROM Field f, Galaxy g
WHERE
g.fieldID = f.fieldID
and ( g.flags & (dbo.fPhotoFlags('BINNED1')
+ dbo.fPhotoFlags('BINNED2')
+ dbo.fPhotoFlags('BINNED4')) ) > 0
and ( g.flags & (dbo.fPhotoFlags('BLENDED')
+ dbo.fPhotoFlags('NODEBLEND')
+ dbo.fPhotoFlags('CHILD')) ) != dbo.fPhotoFlags('BLENDED')
and ( g.flags & (dbo.fPhotoFlags('COSMIC_RAY')
+ dbo.fPhotoFlags('INTERP')) ) = 0
and f.psfWidth_r < 1.5
and (g.i - g.z > 1.0 ) -- i and z in primary tables DO NOT include extinction</textarea><textarea style="display:none" id="q_733458258">-- A version of the LRG sample.
-- by James Annis.
-- Another query with many conditions and flag tests.
SELECT TOP 100
run,
camCol,
rerun,
field,
objID,
ra,
dec
FROM Galaxy
WHERE ( ( flags & (dbo.fPhotoFlags('BINNED1')
+ dbo.fPhotoFlags('BINNED2')
+ dbo.fPhotoFlags('BINNED4')) ) > 0
and ( flags & (dbo.fPhotoFlags('BLENDED')
+ dbo.fPhotoFlags('NODEBLEND')
+ dbo.fPhotoFlags('CHILD')) ) != dbo.fPhotoFlags('BLENDED')
and ( flags & (dbo.fPhotoFlags('EDGE')
+ dbo.fPhotoFlags('SATURATED')) ) = 0
and petroMag_i > 17.5
and (petroMag_r > 15.5 or petror50_r > 2)
and (petroMag_r > 0 and g > 0 and r > 0 and i > 0)
and ( (petroMag_r-extinction_r) < 19.2
and (petroMag_r - extinction_r <
(13.1 + (7/3) * (dered_g - dered_r) + 4 * (dered_r - dered_i) - 4 * 0.18) )
and ( (dered_r - dered_i - (dered_g - dered_r)/4 - 0.18) < 0.2)
and ( (dered_r - dered_i - (dered_g - dered_r)/4 - 0.18) > -0.2)
--dered_ quantities already include extinction
and ( (petroMag_r - extinction_r +
2.5 * LOG10(2 * 3.1415 * petror50_r * petror50_r)) < 24.2) )
or ( (petroMag_r - extinction_r < 19.5)
and ( (dered_r - dered_i - (dered_g - dered_r)/4 - 0.18) > (0.45 - 4 * (dered_g - dered_r)) )
and ( (dered_g - dered_r) > (1.35 + 0.25 * (dered_r - dered_i)) ) )
and ( (petroMag_r - extinction_r +
2.5 * LOG10(2 * 3.1415 * petror50_r * petror50_r) ) < 23.3 ) )</textarea><textarea style="display:none" id="q_1195635002">-- Find galaxies with specific spectra.
-- Namely, they have an equivalent width in
-- H_alpha > 40 Angstroms. We want object ID's from the photometry (Galaxy)
-- but constraints from spectroscopy. The line widths and IDs are stored in
-- SpecLine. --This is a simple query, but now we are using three tables. The
-- spectroscopy tables of measured lines are arranged non-intuitively, and we
-- urge users to read about them on the DAS help pages. --IMPORTANT NOTE:
-- Each spectroscopic object now has a match to at least two photometric
-- objects, one in Target and one in Best. Therefore, when performing a join
-- between spectroscopic photometric objects, you must specify either
-- PhotoObj.ObjID=SpecObj.bestObjID or PhotoObj.ObjID = SpecObj.targetObjID.
-- Normally, the default photometric database is BEST, so you will want to use
-- SpecObj.bestObjID
--
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT G.ObjID -- we want the photometric ObjID
FROM Galaxy as G, -- G is the galaxy
SpecObj as S, -- S is the spectra of galaxy G
SpecLine as L, -- L is a line of S
SpecLineNames as LN -- the names of the lines
WHERE G.ObjID = S.bestObjID -- connect the galaxy to the spectrum
and S.SpecObjID = L.SpecObjID -- and the spectral line L is detected in the spectrum
and L.LineId = LN.value -- L is the H alpha line
and LN.name = 'Ha_6565'
and L.ew > 40 -- and H alpha is at least 40 angstroms wide.
</textarea><textarea style="display:none" id="q_792880405">-- Find galaxies with more specific spectra.
-- Same as prior query, but also require weak Hbeta line (Halpha/Hbeta > 20.)
--
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT G.ObjID -- return qualifying galaxies
FROM Galaxy as G, -- G is the galaxy
SpecObj as S, -- S is the spectra of galaxy G
SpecLine as L1, -- L1 is a line of S
SpecLine as L2, -- L2 is a second line of S
specLineNames as LN1, -- the names of the lines (Halpha)
specLineNames as LN2 -- the names of the lines (Hbeta)
WHERE G.ObjID = S.BestObjID -- connect the galaxy to the spectrum
and S.SpecObjID = L1.SpecObjID -- L1 is a line of S.
and S.SpecObjID = L2.SpecObjID -- L2 is a line of S.
and L1.LineId = LN1. value
and LN1.name = 'Ha_6565' -- L1 is the H alpha line
and L2.LineId = LN2.value -- L2 is the H alpha line
and LN2.name = 'Hb_4863' --
and L1.ew > 200 -- BIG Halpha
and L2.ew > 10 -- significant Hbeta emission line
and L2.ew * 20 < L1.ew -- Hbeta is comparatively small
</textarea><textarea style="display:none" id="q_1564994359">-- Find binary stars with specific colors.
-- At least one of them should have the colors of a white dwarf.
SELECT TOP 100 s1.objID as s1, s2.objID as s2
FROM Star S1, -- S1 is the white dwarf
Neighbors N, -- N is the precomputed neighbors links
Star S2 -- S2 is the second star
WHERE S1.objID = N. objID -- S1 and S2 are neighbors-within 30 arc sec
and S2.objID = N.NeighborObjID
and N.neighborType = dbo.fPhotoType('Star') -- and S2 is a star
and N.distance < .05 -- the 3 arcsecond test
and ((S1.u - S1.g) < 0.4 ) -- and S1 meets Paul Szkodys color cut for
and (S1.g - S1.r) < 0.7 -- white dwarfs.
and (S1.r - S1.i) > 0.4
and (S1.i - S1.z) > 0.4
</textarea><textarea style="display:none" id="q_491051768">-- Find quasars with a broad absorption line and a nearby galaxy.
-- within 10 arcseconds.
-- Return both the quasars and the galaxies.
--
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT Q.BestObjID as Quasar_candidate_ID , G.ObjID as Galaxy_ID, N.distance
FROM SpecObj as Q, -- Q is the specObj of the quasar candidate
Neighbors as N, -- N is the Neighbors list of Q
Galaxy as G, -- G is the nearby galaxy
SpecClass as SC, -- Spec Class
SpecLine as L, -- L is the broad line we are looking for
SpecLineNames as LN -- Line Name
WHERE Q.SpecClass =SC.value -- Q is a QSO
and SC.name in ('QSO', 'HIZ_QSO') -- Spectrum says "QSO"
and Q.SpecObjID = L.SpecObjID -- L is a spectral line of Q.
and L.LineID = LN.value -- line found and
and LN.Name != 'UNKNOWN' -- not not identified
and L.ew < -10 -- but its a prominent absorption line
and Q.BestObjID = N.ObjID -- N is a neighbor record
and G.ObjID = N.NeighborObjID -- G is a neighbor of Q
and N.distance < 10.0/60 -- and it is within 10 arcseconds of the Q.
</textarea><textarea style="display:none" id="q_453518089">-- Find galaxies without saturated pixels within 1' of a given point.
-- ra=185.0, dec=-0.5. This query uses a function fGetNearbyObjEq,
-- which takes 3 arguments (ra,dec, distance in arcmin); this function uses
-- the Neighbors table. The Neighbors table and the Galaxy table have in
-- common the objID, so we have to select objects from both where the objIDs
-- are the same. The output of the function is a table with the Galaxy Object
-- ID and distance in arcmin from the input. This query introduces the use of
-- a JOIN to combine table contents. Also, we use the 'orDER BY' syntax,
-- which will sort the output.
SELECT TOP 100 G.objID, GN.distance
FROM Galaxy as G
JOIN dbo.fGetNearbyObjEq(185.,-0.5, 1) as GN -- this function outputs a table, so we have to do a join
on G.objID = GN.objID -- get objects from temporary neighbors table GN with desired ObjID
WHERE (G.flags & dbo.fPhotoFlags('saturated')) = 0 -- and the object is not saturated. f.PhotoFlags is a function that interprets the flag bits.
ORDER BY distance -- sort these by distance
</textarea><textarea style="display:none" id="q_1011044940">-- Ellipticals with odd lines.
-- Find all elliptical galaxies with spectra that have an anomalous
-- emission line. This query introduces the SQL syntax DISTINCT, which will
-- return only one instance of the requested parameter (ObjID, in this case),
-- because our query may return the same object more than once. This is also
-- the first nested query, where we use one SELECT (the inner one) to get a
-- group of objects we are not interested in. The outer SELECT includes the
-- new syntax 'not in', which is used to perform the exclusion.
--
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT DISTINCT G.ObjID -- return qualifying galaxies
FROM
Galaxy as G, -- G is the galaxy
SpecObjAll as S, -- S is the spectra of galaxy G
SpecLineAll as L, -- L is a line of S
-- we must use SpecLineAll because SpecLine only has ID's lines
XCRedshift as XC -- the template cross-correlation redshift
WHERE G.ObjID = S.bestObjID -- connect galaxy to the spectrum
and S.SpecObjID = L.SpecObjID -- The line L must be in the spectrum S
and S.SpecObjID = XC.SpecObjID -- and there is a crosscorrelation redshift
and XC.tempNo = 8 -- Template('Elliptical') -- best Cross correlation template used is "elliptical"
and L.LineID = 0
and L.ew > 10 -- and the line is prominent by some definition, in this case, the equivalent width is over 10 Angstroms
and S.SpecObjID not in (
-- insist that there are no other lines
SELECT S.SpecObjID -- This is the chosen line.
FROM SpecLine as L1 -- L1 is another line...
-- by using SpecLine, we are automatically requiring that the line
-- be identified
WHERE S.SpecObjID = L1.SpecObjID -- ...for this object...
and abs(L.wave - L1.wave) <.01
-- ...at nearly the same wavelength...
)
</textarea><textarea style="display:none" id="q_1835462071">-- Search near BCG galaxies.
-- For each galaxy in the BCG data set (brightest cluster galaxy),
-- in 160<right ascension<170, -25<declination<35 count the number of
-- galaxies within 30" of it that have a photoz within 0.05
-- of that galaxy.
-- An extremely complex WHERE clause.
SELECT G.objID, count(N.NeighborObjID) as pop
FROM Galaxy as G, -- first gravitational lens candidate
Neighbors as N, -- precomputed list of neighbors
Galaxy as U, -- a neighbor galaxy of G
photoZ as Gpz, -- photoZ of G.
photoZ as Npz -- Neighbor photoZ
WHERE G.ra between 160 and 170
and G.dec between -5 and 5
and G.objID = N.objID -- connect G and U via the neighbors table
and U.objID = N.neighborObjID -- so that we know G and U are within
and N.objID < N.neighborObjID -- 30 arcseconds of one another.
and G.objID = Gpz.objID
and U.objID = Npz.objID
and abs(Gpz.Z - Npz.Z) < 0.05 -- restrict the photoZ differences
and (G.flags & (dbo.fPhotoFlags('BINNED1') + dbo.fPhotoFlags('BINNED2') + dbo.fPhotoFlags('BINNED4'))) > 0
--and it is detected from at least one of the binned images
and (G.flags & ( dbo.fPhotoFlags('BLENDED') + dbo.fPhotoFlags('NODEBLEND') + dbo.fPhotoFlags('CHILD'))) != dbo.fPhotoFlags('BLENDED')
--and, if it is blended, it is either a child or not deblended further ??
and (G.flags & (dbo.fPhotoFlags('EDGE') + dbo.fPhotoFlags('SATURATED'))) = 0
-- and it is not near a ccd edge or saturated, where measurements may be bad
-- and apply color cut for a BCG courtesy of James Annis of Fermilab
and G.petroMag_i > 17.5
and (G.petroMag_r > 15.5 or G.petror50_r > 2)
and (G.petroMag_r < 30 and G.g < 30 and G.r < 30 and G.i < 30)
and (G.r < 19.2
and ( 1=1 or -- huh?
(G.r < (13.1 + (7/3)*(G.g - G.r) +
-- deRed_r < 13.1 + 0.7 / 0.3 * deRed_gr
4 *(G.r - G.i - 0.18 ))
-- 1.2 / 0.3 * deRed_ri
and (( G.r - G.i - (G.g - G.r)/4 - 0.18) BETWEEN -0.2 and 0.2 )
and ((G.r +
-- petSB - deRed_r + 2.5 log10(2Pi*petror50^2)
2.5 * LOG( 2 * 3.1415 * G.petror50_r * G.petror50_r )) < 24.2 )
)
or
( (G.r < 19.5 )
and (( G.r - G.i -(G.g - G.r)/4 -.18) >
-- - deRed_gr/4 - 0.18
-- cperp = deRed_ri
(0.45 - 4*( G.g - G.r)))
-- 0.45 - deRed_gr/0.25
and ((G.g - G.r) > ( 1.35 + 0.25 *(G.r - G.i)))
and ((G.r +
-- petSB - deRed_r + 2.5 log10(2Pi*petror50^2)
2.5 * LOG( 2 * 3.1415 * G.petror50_r * G.petror50_r )) < 23.3 )
)) )
group by G.objID
</textarea><textarea style="display:none" id="q_715981218">-- Broadest line of each spectrum with its ID.
-- (or more generally, all the columns for
-- the spectral line with the highest/lowest something)? The line width is
-- stored in the column sigma, the identification is in the column restwave.
-- (Sebastian Jester )
--
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT
L.specObjId,
L.specLineID,
sMax.Maxwidth -- get the spectroscopic object ID, the line ID, and the width
FROM specLine L,
(SELECT specObjID,
Max(waveMax-waveMin) as MaxWidth
-- Define MaxWidth as the largest difference in the min and max wavelength of
-- an identified line, using the built-in Max function of SQL
FROM SpecLine
GROUP BY specObjID) as sMax
-- sMax contains a single specObjID and MaxWidth. Remember that for each line
-- identified in a given object's spectrum, there is an entry in
-- SpecLine. This means that each specObjID appears many times in SpecLine,
-- once for each line found, and they must be aggregated before performing any
-- operation such as Max. The GROUP BY is thus NECESSARY.
-- The upper FROM clause is telling us we will use the table SpecLine and this
-- new output called sMax, which contains one entry with the SpecObjID and
-- MaxWidth. If we used some other function instead of 'Max', such as 'top
-- 10', sMax would have more than row.
WHERE
L.specObjID = sMax.specObjID
and (L.waveMax-L.waveMin) = sMax.MaxWidth
-- Just as with the specObjID, each specLineID appears many times in specLine.
-- This final WHERE clause makes sure we get the one specLineID from SpecObj
-- which matches the unique combination of specObjID and MaxWidth in sMax.
</textarea><textarea style="display:none" id="q_1104283183">-- Gridded galaxy counts and masks. Actually consists of TWO queries:
-- 1) Create a gridded count of galaxies with u-g > 1 and r < 21.5 over -1 < dec < 1,
-- and 179 < R.A. < 181, on a grid, and create a map of masks over the same grid.
-- Scan the table for galaxies and group them in cells 2 arc-minuteson a side. Provide
-- predicates for the color restrictions on u-g and r and to limit the search to the
-- portion of the sky defined by the right ascension and declination conditions. Return
-- the count of qualifying galaxies in each cell.
-- 2) Run another query with the same grouping, but with a predicate to include only
-- objects such as satellites, planets, and airplanes that obscure the cell. The second
-- query returns a list of cell coordinates that serve as a mask for the first query.
--- First find the gridded galaxy count (with the color cut)
--- In local tangent plane, ra/cos(dec) is a linear degree.
SELECT cast((ra/cos(cast(dec*30 as int)/30.0))*30 as int)/30.0 as raCosDec,
cast(dec*30 as int)/30.0 as dec,
count(*) as pop
FROM Galaxy as G
JOIN dbo.fHTMCoverRegion('CHULL J2000 179 -1 179 1 181 1 181 -1') AS T
ON G.htmID BETWEEN T.HTMIDstart AND T. HTMIDend
WHERE ra between 179 and 181
and dec between -1 and 1
and u-g > 1
and r < 21.5
GROUP BY cast((ra/cos(cast(dec*30 as int)/30.0))*30 as int)/30.0,
cast(dec*30 as int)/30.0
-- now build mask grid.
-- This is a separate query if no temp tables can be made
SELECT cast((ra/cos(cast(dec*30 as int)/30.0))*30 as int)/30.0 as raCosDec,
cast(dec*30 as int)/30.0 as dec,
count(*) as pop
FROM PhotoObj as PO
JOIN dbo.fHTMCoverRegion('CHULL J2000 179 -1 179 1 181 1 181 -1') AS T
ON PO.htmID BETWEEN T.HTMIDstart AND T.HTMIDend
JOIN PhotoType as PT ON PO.type = PT.value
WHERE
ra between 179 and 181
and dec between -1 and 1
and PT.name in ('COSMIC_RAY', 'DEFECT', 'GHOST', 'TRAIL', 'UNKNOWN')
GROUP BY cast((ra/cos(cast(dec*30 as int)/30.0))*30 as int)/30.0,
cast(dec*30 as int)/30.0 </textarea><textarea style="display:none" id="q_1837021711">-- Create a count of galaxies for each of the HTM triangles.
-- Galaxies should satisfy a certain color cut,
-- like 0.7u-0.5g-0.2i<1.25 && r<21.75, output it in a form
-- adequate for visualization.
SELECT (htmID / power(2,24)) as htm_8 ,
-- group by 8-deep HTMID (rshift HTM by 12)
avg(ra) as ra,
avg(dec) as [dec],
count(*) as pop -- return center point and count for display
FROM Galaxy -- only look at galaxies
WHERE (0.7*u - 0.5*g - 0.2*i) < 1.25 -- meeting this color cut
and r < 21.75 -- brighter than 21.75 magnitude in red band.
group by (htmID /power(2,24)) -- group into 8-deep HTM buckets.
</textarea><textarea style="display:none" id="q_2135502459">-- Find stars with multiple measurements with magnitude variations >0.1.
-- Note that this runs very slowly unless explicit workarounds are included
-- for some SQLServer Optimizer bugs, which are NOT included here
SELECT TOP 100
S1.objID as objID1, S2.objID as ObjID2 -- select object IDs of star and its pair
FROM Star as S1, -- the primary star
photoObj as S2, -- the second observation of the star
neighbors as N -- the neighbor record
WHERE S1.objID = N.objID -- insist the stars are neighbors
and S2.objID = N.neighborObjID -- using precomputed neighbors table
and distance < 0.5/60 -- distance is 0.5 arc second or less
and S1.run != S2.run -- observations are two different runs
and S2.type = dbo.fPhotoType('Star') -- S2 is indeed a star
and S1.u between 1 and 27 -- S1 magnitudes are reasonable
and S1.g between 1 and 27
and S1.r between 1 and 27
and S1.i between 1 and 27
and S1.z between 1 and 27
and S2.u between 1 and 27 -- S2 magnitudes are reasonable.
and S2.g between 1 and 27
and S2.r between 1 and 27
and S2.i between 1 and 27
and S2.z between 1 and 27
and ( -- and one of the colors is different.
abs(S1.u-S2.u) > .1 + (abs(S1.Err_u) + abs(S2.Err_u))
or abs(S1.g-S2.g) > .1 + (abs(S1.Err_g) + abs(S2.Err_g))
or abs(S1.r-S2.r) > .1 + (abs(S1.Err_r) + abs(S2.Err_r))
or abs(S1.i-S2.i) > .1 + (abs(S1.Err_i) + abs(S2.Err_i))
or abs(S1.z-S2.z) > .1 + (abs(S1.Err_z) + abs(S2.Err_z))
)
</textarea><textarea style="display:none" id="q_114193719">-- This query uses the new SQL Server 2005 CROSS APPLY and OUTER APPLY
-- constructs to apply a table-valued function to the results of a query.
-- In this example, we use the fFootPrintEq function which returns a list
-- of SDSS regions that intersect the area specified by the RA, dec and
-- radius, or NULL if the area is outside the SDSS footprint.
-- For each point in the input list, in this case the result of a query
-- on PhotoObj, return "yes" or "no" depending on whether the point is in
-- the SDSS footprint or not, and any other needed columns.
SELECT top 100 objID, ra, dec,
(case when p.type is null then 'NO' else 'YES' end) as found
FROM PhotoObj AS p
OUTER APPLY dbo.fFootprintEq(ra,dec,0.1)
WHERE (ra between 179.5 and 182.3) and (dec between -1.0 and 1.8)
</textarea>
<textarea style="display:none" id="q_318573181">-- Find unique objects in an RA/Dec box.
-- PhotoPrimary is a view which selects only unique objects.
-- The full list of good detections including duplicates is in PhotoObj
-- A basic SELECT-FROM-WHERE query.
SELECT TOP 100 objID, -- Get the unique object ID,
field, ra, dec -- the field number, and coordinates
FROM PhotoPrimary -- From the photometric data
WHERE
ra > 185. and ra < 185.1 and dec > 15. and dec < 15.1 </textarea><textarea style="display:none" id="q_2121526033">-- Galaxies meeting two simple criteria.
-- Find all galaxies brighter than r magnitude 22, where the local
-- extinction is > 0.175. This is a simple query that uses a WHERE clause,
-- but now two conditions that must be met simultaneously.
SELECT TOP 10 objID
FROM Galaxy
WHERE
r < 22 -- r IS NOT deredenned
and extinction_r > 0.175 -- extinction more than 0.175
</textarea><textarea style="display:none" id="q_1702999202">-- Find specific types of quasars using spectroscopy.
-- The easiest way to find quasars is by finding objects whose spectra have
-- been classified as quasars. This sample query searches the SpecObj
-- table for the IDs and redshifts of objects with the class column equal to 'QSO'
SELECT TOP 100 specObjID, z
FROM SpecObj
WHERE class = 'QSO' AND zWarning = 0
</textarea><textarea style="display:none" id="q_807954861">-- Using the BETWEEN syntax.
-- Find all galaxies in a certain area of the sky that also meet other
-- criteria in their measured parameters. This query intriduces the
-- BETWEEN construct to specify a range of values.
SELECT TOP 100 objID, ra, dec, cModelMag_g
FROM Galaxy
WHERE ra BETWEEN 178 AND 180
AND dec < 0
AND cModelMag_g BETWEEN 18 AND 19
</textarea><textarea style="display:none" id="q_1601839065">-- Using spatial unit vectors for coordinate cuts.
-- Find galaxies in a given area of the sky, using a coordinate cut
-- in the unit vector cx,cy,cz that corresponds to a specific RA range.
-- Another simple query that uses math in the WHERE clause.
--
-- NOTE: This query must be run in batch mode, i.e. using the Submit button
-- because it takes too long to execute in Quick mode.
SELECT TOP 100 colc_g, colc_r
FROM Galaxy
WHERE
(-0.466 * cx + 0.689 * cy>=0)
and (-0.385 * cx - 0.173 * cy <0)
</textarea><textarea style="display:none" id="q_1407015576">-- Find CVs using colors.
-- Search for Cataclysmic Variables and pre-CVs with White Dwarfs and
-- very late secondaries. Just uses some simple color cuts from Paula Szkody.
-- Another simple query that uses math in the WHERE clause
SELECT TOP 100 run,
camCol,
rerun,
field,
objID,
u, g, r, i, z,
ra, dec -- Just get some basic quantities
FROM PhotoPrimary -- From all primary detections, regardless of class
WHERE u - g < 0.4
and g - r < 0.7
and r - i > 0.4
and i - z > 0.4 -- that meet the color criteria
</textarea><textarea style="display:none" id="q_810186038">-- Getting a subsample of the data.
--
-- Uses the integer short object id (obj) - which is the least significant bits
-- of the long objID - and the '%' operator (remainder) to get every 1000th
-- object.
-- NOTE: THIS IS NOT A TRULY RANDOM SAMPLE!
SELECT TOP 100 u, g, r, i, z
FROM Galaxy with (nolock)
WHERE (objID%1000) = 1
AND (r between 18 and 21)
</textarea><textarea style="display:none" id="q_446289279">-- Low-z QSO candidates using color cuts.
-- from Gordon Richards.
-- Also a simple query with a long WHERE clause.
SELECT TOP 1000 g, run, rerun, camcol, field, objID
FROM
Galaxy
WHERE (
(g <= 22) and
(u-g >= -0.27) and (u-g < 0.71) and
(g-r >= -0.24) and (g-r < 0.35) and
(r-i >= -0.27) and (r-i < 0.57) and
(i-z >= -0.35) and (i-z < 0.70)
)</textarea><textarea style="display:none" id="q_832506840">-- Get object velocities and errors.
-- This is also a simple query that uses a WHERE clause.
-- However, now we perform a more complex mathematical operation.
SELECT TOP 10
run, -- get a bunch of quantities
camCol,
field,
objID,
rowC, colC, rowV, colV, rowVErr, colVErr,
flags,
psfMag_u, psfMag_g, psfMag_r, psfMag_i, psfMag_z,
psfMagErr_u, psfMagErr_g, psfMagErr_r, psfMagErr_i, psfMagErr_z
FROM PhotoPrimary
WHERE ((rowv * rowv) / (rowvErr * rowvErr) +
(colv * colv) / (colvErr * colvErr) > 4)
-- where the velocities are reliable
</textarea><textarea style="display:none" id="q_1549577480">-- Finding galaxies by their emission lines:
--
-- SDSS-III handles searches by spectral lines differently than previous
-- releases. In addition, spectral lines for galaxies and stars are
-- identified through different processes. See the "Spectra of Red
-- Stars" sample query for an example of using stellar spectra.
--
-- Spectral lines for galaxies are calculated using the MPA-JHU
-- spectroscopic reanalysis (Tremonti et al. 2004; Brinchmann et al. 2004)
-- and are stored in the galSpecLine table. For more on how spectral lines
-- of galaxies are found, see the Galspec page of the sdss3.org website.
--
-- This query selects galaxy spectra with high internal reddening,
-- as measured by the standard Balmer decrement technique. It
-- makes use of the galSpec tables for the measurements of
-- galaxy lines. In this case we use galSpecLine, which has
-- emission line measurements.
SELECT
s.plate, s.fiberid, s.mjd, s.z, s.zwarning,
g.h_beta_flux, g.h_beta_flux_err,
g.h_alpha_flux, g.h_alpha_flux_err
FROM GalSpecLine AS g
JOIN dbo.SpecObj AS s ON s.specobjid = g.specobjid
WHERE
h_alpha_flux > h_alpha_flux_err*5
AND h_beta_flux > h_beta_flux_err*5
AND h_beta_flux_err > 0
AND h_alpha_flux > 10.*h_beta_flux
AND s.class = 'GALAXY'
AND s.zwarning = 0
</textarea><textarea style="display:none" id="q_1075597663">-- Moving objects consistent with an asteroid.
-- Also a simple query, but we introduce the 'as' syntax, which allows us to
-- name derived quantities in the result file.
--
-- NOTE: Since asteroids are rare objects in the SDSS data, this query will
-- take a long time to run without the "TOP 10" and should be executed
-- in batch mode (with the Submit button).
SELECT TOP 10
objID,
sqrt( power(rowv,2) + power(colv, 2) ) as velocity
FROM PhotoObj
WHERE
(power(rowv,2) + power(colv, 2)) between 50 and 1000
</textarea><textarea style="display:none" id="q_387047336">-- Find quasars in imaging data.
-- as specified by Xiaohui Fan et.al.
-- A rather straightforward query, just with many conditions.
SELECT TOP 100 run,
camCol,
rerun,
field,
objID,
u, g, r, i, z,
ra, dec
FROM Star -- or Galaxy
WHERE ( u - g > 2.0 or u > 22.3 )
and ( i < 19 )
and ( i > 0 )
and ( g - r > 1.0 )
and ( r - i <
(0.08 + 0.42 * (g - r - 0.96) )
or g - r > 2.26 )
and ( i - z < 0.25 )
</textarea><textarea style="display:none" id="q_464249349">-- Using object counting and logic in a query.
-- Find all objects similar to the colors of a quasar at 5.5<redshift<6.5.
-- An area restriction is added so the query will run in the Quick queue.
SELECT count(*) as 'total',
sum( case when (Type=3) then 1 else 0 end) as 'Galaxies',
sum( case when (Type=6) then 1 else 0 end) as 'Stars',
sum( case when (Type not in (3,6)) then 1 else 0 end) as 'Other'
FROM PhotoPrimary -- for each object
WHERE
(ra between 180 and 190) and (dec between -5 and 5)
and (( u - g > 2.0) or (u > 22.3) ) -- apply the quasar color cut.
and ( i between 0 and 19 )
and ( g - r > 1.0 )
and ( (r - i < 0.08 + 0.42 * (g - r - 0.96)) or (g - r > 2.26 ) )
and ( i - z < 0.25 )
</textarea><textarea style="display:none" id="q_1257775135">-- Find galaxies that are blended with a star.
-- Output the deblended galaxy magnitudes.
-- This query introduces the use of multiple tables or views. You can assign
-- nicknames to tables as in the FROM clause below. Since you are using
-- multiple tables, you must specify which table each quantity in the SELECT
-- clause comes from. The query illustrates the JOIN syntax between
-- the two tables, which requires that a common quantity that is present in
-- both tables be equal, in this case their common parent object.
SELECT top 1000 G.ObjID, G.u, G.g, G.r, G.i, G.z
FROM Galaxy G -- compare Galaxy and Star
JOIN Star S ON G.parentID = S.parentID -- using the same parent
WHERE
G.parentID > 0 -- if the galaxy has a "parent", this object was deblended
</textarea><textarea style="display:none" id="q_1773962834">-- Stars selected using Field criteria.
-- Give me the PSF colors of all stars brighter than g=20 that have PSP_STATUS = 2.
-- Another simple multi-table query.
SELECT TOP 1000
s.psfMag_g, -- or whatever you want from each object
s.run,
s.camCol,
s.rerun,
s.field
FROM Star s
JOIN Field f ON s.fieldID = f.fieldID
WHERE
s.psfMag_g < 20
and f.pspStatus = 2
</textarea><textarea style="display:none" id="q_1890051708">-- Objects selected by cuts on three tables.
-- Find the parameters for all objects in a selected field with
-- desired PSF width and range of columns.
-- Now we are using three tables, but it is still a simple query.
SELECT TOP 1000
f.run,
f.rerun,
f.camCol,
f.field,
p.objID,
p.ra,
p.dec,
p.Rowc,
p.Colc,
p.u,
p.modelMagErr_u ,
p.g,
p.modelMagErr_g,
p.r,
p.modelMagErr_r,
p.petroMag_r - p.extinction_r,
p.petroMagErr_r,
p.i,
p.modelMagErr_i,
p.z,
f.psfWidth_r,
r.stripe,
r.strip
FROM
photoObj p
JOIN field f ON f.fieldid = p.fieldid
JOIN run r ON r.run=f.run
WHERE
f.psfWidth_r > 1.2
and p.colc > 400.0
</textarea><textarea style="display:none" id="q_2042342521">-- Find all objects within 30 arcseconds of one another
-- that have very similar colors: that is where the color ratios
-- u-g, g-r, r-I are less than 0.05m. This query introduces the
-- Neighbors table, which is a pre-computed list of the nearest
-- neighbors of each object within 30 arcseconds.
SELECT TOP 10 P.ObjID as objid1, L.ObjID as objid2, N.distance
FROM PhotoPrimary P -- P is the primary object
JOIN Neighbors N ON P.ObjID = N.ObjID -- N is the neighbor link
JOIN PhotoPrimary L ON L.ObjID = N.NeighborObjID -- L is the lens candidate of P
WHERE
P.ObjID < L. ObjID -- avoid duplicates
and abs((P.u-P.g)-(L.u-L.g))<0.05 -- L and P have similar spectra
and abs((P.g-P.r)-(L.g-L.r))<0.05
and abs((P.r-P.i)-(L.r-L.i))<0.05
and abs((P.i-P.z)-(L.i-L.z))<0.05
</textarea><textarea style="display:none" id="q_1271476914">-- Find stars with multiple measurements with magnitude variations >0.1.
-- Note that this runs very slowly unless explicit workarounds are included
-- for some SQLServer Optimizer bugs, which are NOT included here
SELECT TOP 100
S1.objID as objID1, S2.objID as ObjID2 -- select object IDs of star and its pair
FROM Star as S1, -- the primary star
photoObj as S2, -- the second observation of the star
neighbors as N -- the neighbor record
WHERE S1.objID = N.objID -- insist the stars are neighbors
and S2.objID = N.neighborObjID -- using precomputed neighbors table
and distance < 0.5/60 -- distance is 0.5 arc second or less
and S1.run != S2.run -- observations are two different runs
and S2.type = dbo.fPhotoType('Star') -- S2 is indeed a star
and S1.u between 1 and 27 -- S1 magnitudes are reasonable
and S1.g between 1 and 27
and S1.r between 1 and 27
and S1.i between 1 and 27
and S1.z between 1 and 27
and S2.u between 1 and 27 -- S2 magnitudes are reasonable.
and S2.g between 1 and 27
and S2.r between 1 and 27
and S2.i between 1 and 27
and S2.z between 1 and 27
and ( -- and one of the colors is different.
abs(S1.u-S2.u) > .1 + (abs(S1.Err_u) + abs(S2.Err_u))
or abs(S1.g-S2.g) > .1 + (abs(S1.Err_g) + abs(S2.Err_g))
or abs(S1.r-S2.r) > .1 + (abs(S1.Err_r) + abs(S2.Err_r))
or abs(S1.i-S2.i) > .1 + (abs(S1.Err_i) + abs(S2.Err_i))
or abs(S1.z-S2.z) > .1 + (abs(S1.Err_z) + abs(S2.Err_z))
)
</textarea><textarea style="display:none" id="q_162268584">-- Checking for errors using flags.
-- Another useful query is to see if the errors on moving (or
-- apparently moving) objects are correct. For example, it used to be that
-- some known QSOs were being flagged as moving objects. One way to look for
-- such objects is to compare the velocity to the error in velocity and see if
-- the "OBJECT1_MOVED" or "OBJECT2_BAD_MOVING_FIT" is set.
-- This query introduces bitwise logic for flags, and uses the 'as' syntax to
-- make the query more readable. Note that if a flag is not set, the value
-- will be zero. If you want to ensure multiple flags are not set, you can
-- either check that each individually is zero, or that their sum is zero.
-- (From Gordon Richards)
--
-- NOTE: A caveat about using functons (like fPhotoFlags) is that if your
-- query is selecting a very large number of rows (e.g. hundreds of
-- thousands or millions) then it's that many function calls, and
-- this will slow down the query execution significantly. In that
-- case, you should replace the function call with its equivalent
-- binary bitmask, e.g. if you run the query (with Quick button)
-- SELECT (dbo.fPhotoFlags('MOVED') + dbo.fPhotoFlags('BAD_MOVING_FIT'))
-- you will get the value 36507222016, which you can substitute in
-- first line of the WHERE clause below as:
-- (flags & 36507222016) > 0
-- to avoid zillions of function calls.
SELECT TOP 1000
run,
rerun,
camcol,
field,
objID,
ra, dec,
rowv, colv,
rowvErr, colvErr,
i,
(flags & dbo.fPhotoFlags('MOVED')) as MOVED,
(flags & dbo.fPhotoFlags('BAD_MOVING_FIT')) as BAD_MOVING_FIT
FROM Galaxy
WHERE
(flags & (dbo.fPhotoFlags('MOVED') + dbo.fPhotoFlags('BAD_MOVING_FIT'))) > 0
and (rowv * rowv + colv * colv) >=
(rowvErr * rowvErr + colvErr * colvErr)
</textarea><textarea style="display:none" id="q_200158383">-- Elliptical galaxies based on model fits.
-- Find all galaxies with a deVaucouleours profile and the
-- photometric colors consistent with an elliptical galaxy.
-- This query has many conditions, and also shows more of the
-- bitwise logic necessary for dealing with flags.
SELECT TOP 100 ObjID
FROM Galaxy as G
WHERE
G.lnlDev_r > G.lnlExp_r + 0.1
-- the likelihood of the deVaucouleours profile fit is 10% greater than the likelihood of the exponential fit
and G.lnlExp_r > -999
-- and the likelihoods are actually meaningful
and (G.flags & (dbo.fPhotoFlags('BINNED1') + dbo.fPhotoFlags('BINNED2') + dbo.fPhotoFlags('BINNED4'))) > 0
--and it is detected from at least one of the binned images ???
and (G.flags & ( dbo.fPhotoFlags('BLENDED') + dbo.fPhotoFlags('NODEBLEND') + dbo.fPhotoFlags('CHILD'))) != dbo.fPhotoFlags('BLENDED')
--and, if it is blended, it is either a child or not deblended further ??
and (G.flags & (dbo.fPhotoFlags('EDGE') + dbo.fPhotoFlags('SATURATED'))) = 0
-- and it is not near a ccd edge or saturated, where measurements may be bad
and G.petroMag_i > 17.5
-- and it is fainter than 17.5 in i-band
and (G.petroMag_r > 15.5 or G.petror50_r > 2)
and (G.petroMag_r > 0 and G.g > 0 and G.r > 0 and G.i > 0)
and ( (G.petroMag_r - G.extinction_r) < 19.2
and (G.petroMag_r - G.extinction_r <
(13.1 + (7/3)*(G.g - G.r) + 4 *(G.r - G.i) - 4 * 0.18 ) )
and ( (G.r - G.i - (G.g - G.r)/4 - 0.18) < 0.2 )
and ( (G.r - G.i - (G.g - G.r)/4 - 0.18) > -0.2 ) )
or ( (G.petroMag_r - G.extinction_r < 19.5)
and ( (G.r - G.i - (G.g - G.r)/4 - 0.18) >
(0.45 - 4*(G.g - G.r) ) )
and ( (G.g - G.r) > (1.35 + 0.25 *(G.r - G.i) ) ) )
-- and many constraints on colors and mags are met to make it have
-- elliptical-type colors.
</textarea><textarea style="display:none" id="q_220572073">-- Galaxies with bluer centers.
-- by Michael Strauss. For all galaxies
-- with r_Petro < 18, not saturated, not bright, and not edge, give me those
-- with centers appreciably bluer than their outer parts, i.e., define the
-- center color as: u_psf - g_psf and define the outer color as: u_model -
-- g_model; give me all objs which have (u_model - g_model) - (u_psf - g_psf)
-- < -0.4
-- Another flags-based query.
SELECT TOP 1000
colc_u, colc_g, objID
FROM Galaxy
WHERE
( Flags & (dbo.fPhotoFlags('SATURATED') +
dbo.fPhotoFlags('BRIGHT') +
dbo.fPhotoFlags('EDGE')) ) = 0
and petrorad_r < 18
and ((colc_u - colc_g) - (psfMag_u - psfMag_g)) < -0.4</textarea><textarea style="display:none" id="q_454660149">-- Diameter-limited sample of galaxies
-- from James Annis.
-- Another query that makes extensive use of photo flags to get a sample
-- of galaxies within a size range as specified by their i-band Petrosian
-- radius.
SELECT TOP 100
run,
camCol,
rerun,
field,
objID,
ra,
dec
FROM Galaxy
WHERE ( flags & (dbo.fPhotoFlags('BINNED1')
+ dbo.fPhotoFlags('BINNED2')
+ dbo.fPhotoFlags('BINNED4')) ) > 0
and ( flags & (dbo.fPhotoFlags('BLENDED')
+ dbo.fPhotoFlags('NODEBLEND')
+ dbo.fPhotoFlags('CHILD')) ) != dbo.fPhotoFlags('BLENDED')
and ( ( (flags & dbo.fPhotoFlags('NOPETRO') = 0)
and petrorad_i > 15)
or ( (flags & dbo.fPhotoFlags('NOPETRO') > 0)
and petrorad_i > 7.5)
or ( (flags & dbo.fPhotoFlags('TOO_LARGE') > 0)
and petrorad_i > 2.5)
or
( (flags & dbo.fPhotoFlags('SATURATED') = 0)
and petrorad_i > 17.5) )
</textarea><textarea style="display:none" id="q_1221376687">-- Extremely red galaxies.
-- from James Annis.
-- Similar to the diameter limited sample query but selects galaxies that
-- are red (i-z color greater than a certain threshold).
SELECT TOP 1000
g.run,
g.camCol,
g.rerun,
g.field,
g.objID,
g.ra, g.dec
FROM Field f, Galaxy g
WHERE
g.fieldID = f.fieldID
and ( g.flags & (dbo.fPhotoFlags('BINNED1')
+ dbo.fPhotoFlags('BINNED2')
+ dbo.fPhotoFlags('BINNED4')) ) > 0
and ( g.flags & (dbo.fPhotoFlags('BLENDED')
+ dbo.fPhotoFlags('NODEBLEND')
+ dbo.fPhotoFlags('CHILD')) ) != dbo.fPhotoFlags('BLENDED')
and ( g.flags & (dbo.fPhotoFlags('COSMIC_RAY')
+ dbo.fPhotoFlags('INTERP')) ) = 0
and f.psfWidth_r < 1.5
and (g.i - g.z > 1.0 )
</textarea><textarea style="display:none" id="q_663779516">-- A version of the LRG sample.
-- by James Annis.
-- Another query with many conditions and flag tests that selects Luminous
-- Red Galaxies (LRGs).
SELECT TOP 100
run,
camCol,
rerun,
field,
objID,
ra,
dec
FROM Galaxy
WHERE ( ( flags & (dbo.fPhotoFlags('BINNED1')
+ dbo.fPhotoFlags('BINNED2')
+ dbo.fPhotoFlags('BINNED4')) ) > 0
and ( flags & (dbo.fPhotoFlags('BLENDED')
+ dbo.fPhotoFlags('NODEBLEND')
+ dbo.fPhotoFlags('CHILD')) ) != dbo.fPhotoFlags('BLENDED')
and ( flags & (dbo.fPhotoFlags('EDGE')
+ dbo.fPhotoFlags('SATURATED')) ) = 0
and petroMag_i > 17.5
and (petroMag_r > 15.5 or petror50_r > 2)
and (petroMag_r > 0 and g > 0 and r > 0 and i > 0)
and ( (petroMag_r-extinction_r) < 19.2
and (petroMag_r - extinction_r <
(13.1 + (7/3) * (dered_g - dered_r) + 4 * (dered_r - dered_i) - 4 * 0.18) )
and ( (dered_r - dered_i - (dered_g - dered_r)/4 - 0.18) < 0.2)
and ( (dered_r - dered_i - (dered_g - dered_r)/4 - 0.18) > -0.2)
--dered_ quantities already include extinction
and ( (petroMag_r - extinction_r +
2.5 * LOG10(2 * 3.1415 * petror50_r * petror50_r)) < 24.2) )
or ( (petroMag_r - extinction_r < 19.5)
and ( (dered_r - dered_i - (dered_g - dered_r)/4 - 0.18) > (0.45 - 4 * (dered_g - dered_r)) )
and ( (dered_g - dered_r) > (1.35 + 0.25 * (dered_r - dered_i)) ) )
and ( (petroMag_r - extinction_r +
2.5 * LOG10(2 * 3.1415 * petror50_r * petror50_r) ) < 23.3 ) )
</textarea><textarea style="display:none" id="q_338186821">-- Spectra of Red Stars
--
-- SDSS-III handles searches by spectral lines differently than previous
-- releases. In addition, spectral lines for galaxies and stars are
-- identified through different processes. See the "Galaxies with
-- Emission Lines" sample query for an example of using galaxy spectra.
--
-- Spectral lines for stars are calculated using the SEGUE Stellar Parameter
-- Pipeline (SSPP; Lee et al. 2008) and are stored in the sppLines
-- table. For more on how spectral lines of stars are found, see
-- the SSPP page of the sdss3.org website.
-- This query selects red stars (spectral type K), with large
-- CaII triplet eq widths, with low errors on the CaII triplet
-- equivalent widths.
SELECT
sl.plate,sl.mjd,sl.fiber,
sl.caIIKside,sl.caIIKerr,sl.caIIKmask,
sp.fehadop,sp.fehadopunc,sp.fehadopn,
sp.loggadopn,sp.loggadopunc
FROM sppLines AS sl
JOIN sppParams AS sp ON sl.specobjid = sp.specobjid
WHERE
fehadop < -3.5
AND fehadopunc between 0.01
and 0.5 and fehadopn > 3
</textarea><textarea style="display:none" id="q_284125386">-- Galaxy counts on HTM grid.
--
-- Create a count of galaxies for each of the Hierarchical Triangular Mesh (HTM) triangles.
-- Galaxies should satisfy a certain color cut like 0.7u-0.5g-0.2i<1.25 && r<21.75, output
-- it in a form adequate for visualization.
SELECT (htmID / power(2,24)) as htm_8 ,
-- group by 8-deep HTMID (rshift HTM by 12)
avg(ra) as ra,
avg(dec) as [dec],
count(*) as pop -- return center point and count for display
FROM Galaxy -- only look at galaxies
WHERE
-- RA/dec cut added to make query run in Quick mode
(ra between 180 and 181 and dec between -1 and 1) and
(0.7*u - 0.5*g - 0.2*i) < 1.25 -- meeting this color cut
and r < 21.75 -- brighter than 21.75 magnitude in red band.
group by (htmID /power(2,24)) -- group into 8-deep HTM buckets.
</textarea><textarea style="display:none" id="q_1363234497">-- Binary Stars Colors.
--
-- Find binary stars with specific colors.
-- At least one of them should have the colors (meets Paul Szkody's color cut) of a white dwarf.
SELECT TOP 100 s1.objID as s1, s2.objID as s2
FROM Star S1 -- S1 is the white dwarf
JOIN Neighbors N ON S1.objID = N. objID -- N is the precomputed neighbors link
JOIN Star S2 ON S2.objID = N.NeighborObjID -- S2 is the second star
WHERE
N.neighborType = dbo.fPhotoType('Star') -- and S2 is a star
and N.distance < .05 -- the 3 arcsecond test
and ((S1.u - S1.g) < 0.4 ) -- and S1 meets the color cut for
and (S1.g - S1.r) < 0.7 -- white dwarfs.
and (S1.r - S1.i) > 0.4
and (S1.i - S1.z) > 0.4
</textarea><textarea style="display:none" id="q_911927524">-- Galaxies unsaturated near (given) coordinates.
--
-- Find galaxies without saturated pixels within 1' of a given point.
-- ra=185.0, dec=-0.5. This query uses a function fGetNearbyObjEq,
-- which takes 3 arguments (ra,dec, distance in arcmin); this function uses
-- the Neighbors table. The Neighbors table and the Galaxy table have in
-- common the objID, so we have to select objects from both where the objIDs
-- are the same. The output of the function is a table with the Galaxy Object
-- ID and distance in arcmin from the input. This query introduces the use of
-- a JOIN to combine table contents. Also, we use the 'ORDER BY' syntax,
-- which will sort the output.
SELECT TOP 100 G.objID, GN.distance
FROM Galaxy AS G
JOIN dbo.fGetNearbyObjEq(185.,-0.5, 1) AS GN -- this function outputs a table, so we have to do a join
ON G.objID = GN.objID -- get objects from temporary neighbors table GN with desired ObjID
WHERE
(G.flags & dbo.fPhotoFlags('saturated')) = 0 -- and the object is not saturated. f.PhotoFlags is a function that interprets the flag bits.
ORDER BY distance -- sort these by distance
</textarea><textarea style="display:none" id="q_2046113808">-- Search near BCG galaxies.
--
-- For each galaxy in the BCG data set (brightest cluster galaxy),
-- in 160<right ascension<170, -25<declination<35 count the number of
-- galaxies within 30" of it that have a photoz within 0.05
-- of that galaxy.
-- This query has a very complex WHERE clause.
SELECT TOP 1000 G.objID, COUNT(N.NeighborObjID) AS pop
FROM Galaxy AS G -- first gravitational lens candidate
JOIN Neighbors AS N ON G.objID = N.objID -- precomputed list of neighbors
JOIN Galaxy AS U ON U.objID = N.neighborObjID -- a neighbor galaxy of G
JOIN photoZ AS Gpz ON G.objID = Gpz.objID -- photoZ of G.
JOIN photoZ AS Npz ON U.objID = Npz.objID -- neighbor photoZ
WHERE
G.ra BETWEEN 160 AND 170
AND G.dec BETWEEN -5 AND 5
AND N.objID < N.neighborObjID -- 30 arcseconds of one another.
AND ABS(Gpz.Z - Npz.Z) < 0.05 -- restrict the photoZ differences
AND (G.flags & (dbo.fPhotoFlags('BINNED1') + dbo.fPhotoFlags('BINNED2') + dbo.fPhotoFlags('BINNED4'))) > 0
--and it is detected from at least one of the binned images
AND (G.flags & ( dbo.fPhotoFlags('BLENDED') + dbo.fPhotoFlags('NODEBLEND') + dbo.fPhotoFlags('CHILD'))) != dbo.fPhotoFlags('BLENDED')
--and, if it is blended, it is either a child or not deblended further ??
AND (G.flags & (dbo.fPhotoFlags('EDGE') + dbo.fPhotoFlags('SATURATED'))) = 0
-- and it is not near a ccd edge or saturated, where measurements may be bad
-- and apply color cut for a BCG courtesy of James Annis of Fermilab
AND G.petroMag_i > 17.5
AND (G.petroMag_r > 15.5 or G.petror50_r > 2)
AND (G.petroMag_r < 30 AND G.g < 30 AND G.r < 30 AND G.i < 30)
AND (G.r < 19.2
AND ( 1=1 or -- huh?
(G.r < (13.1 + (7/3)*(G.g - G.r) +
-- deRed_r < 13.1 + 0.7 / 0.3 * deRed_gr
4 *(G.r - G.i - 0.18 ))
-- 1.2 / 0.3 * deRed_ri
AND (( G.r - G.i - (G.g - G.r)/4 - 0.18) BETWEEN -0.2 AND 0.2 )
AND ((G.r +
-- petSB - deRed_r + 2.5 log10(2Pi*petror50^2)
2.5 * LOG( 2 * 3.1415 * G.petror50_r * G.petror50_r )) < 24.2 )
)
or
( (G.r < 19.5 )
AND (( G.r - G.i -(G.g - G.r)/4 -.18) >
-- - deRed_gr/4 - 0.18
-- cperp = deRed_ri
(0.45 - 4*( G.g - G.r)))
-- 0.45 - deRed_gr/0.25
AND ((G.g - G.r) > ( 1.35 + 0.25 *(G.r - G.i)))
AND ((G.r +
-- petSB - deRed_r + 2.5 log10(2Pi*petror50^2)
2.5 * LOG( 2 * 3.1415 * G.petror50_r * G.petror50_r )) < 23.3 )
)) )
GROUP BY G.objID
</textarea><textarea style="display:none" id="q_1348920221">-- The detectionIndex table contains all detections of a given physical object,
-- which is uniquely identified by the "thingid". In order to extract photometry,
-- you need a join with the PhotoObjAll table, using the objid.
-- There is also a flag field called isPrimary, which is 1 for the object that
-- is found on a primary polygon/field, all the other detections have 0 in this field.
-- Here is a compound query to find all time series around a certain object with a thingid= 97423000
SELECT
LTRIM(STR(mjd_r,20,2)) AS MJD,
dbo.fSDSS(p.objId) AS ID,
modelMag_g, modelMagErr_g,
modelMag_r, modelMagErr_r,
modelMag_i, modelMagErr_i, p.ra, p.dec
INTO #list
FROM detectionindex d
JOIN PhotoObjAll p ON d.objid=p.objid
JOIN Field f ON p.fieldid=f.fieldid
WHERE d.thingid=97423000
ORDER BY 1
GO
--
-- Now find objects near each of the detections
--
SELECT a.*, b.*
FROM #list a
CROSS APPLY dbo.fGetNearbyObjEq(a.ra, a.dec, 0.1) b
</textarea><textarea style="display:none" id="q_619277145">-- The APOGEE survey is conducted along a number of different lines of sight,
-- each referred to as as a "field" or "location" (interchangeably). Each
-- field has a name and an id number (LOCATION_ID). The stars in each field
-- are observed multiple times on multiple visits, on different MJDs. These
-- may involve one or more physical plug plates.
-- To find all the plate visits, one can search as follows (for LOCATION_ID
-- 4105):
SELECT plate, mjd FROM apogeePlate WHERE location_id=4105
-- The same field can be searched by its name (in this case 'M13'):
SELECT plate, mjd FROM apogeePlate WHERE name = 'M13'
</textarea><textarea style="display:none" id="q_1575944052">-- Get ASPCAP parameters and errors for all stars that were targeted as part
-- of the main APOGEE survey:
-- The stellar parameters are available for all stars that had ASPCAP run
-- on them. However, this includes some spectra known to be bad as well as
-- stars targeted as part of ancillary programs of various
-- sorts. Restricting to the good, main survey targets requires checking on
-- target and catalog flags, as in the examples below:
SELECT TOP 100
s.apogee_id,s.ra, s.dec, s.glon, s.glat,
s.vhelio_avg,s.vscatter,
a.teff, a.teff_err, a.logg, a.logg_err, a.metals, a.metals_err,
a.alphafe, a.alphafe_err,
dbo.fApogeeAspcapFlagN(a.aspcapflag),
dbo.fApogeeStarFlagN(s.starflag)
FROM apogeeStar s
JOIN aspcapStar a on a.apstar_id = s.apstar_id
WHERE (a.aspcapflag & dbo.fApogeeAspcapFlag('STAR_BAD')) = 0 and
s.commiss = 0 and
(s.apogee_target1 &
(dbo.fApogeeTarget1('APOGEE_SHORT')+
dbo.fApogeeTarget1('APOGEE_INTERMEDIATE')+
dbo.fApogeeTarget1('APOGEE_LONG'))) != 0
</textarea><textarea style="display:none" id="q_873427785">-- Get parameters for all stars with [Fe/H] < -2 with no BAD FLAGS set:
-- You can also select a subset of the stars based on their
-- properties. This example finds a set of metal-poor stars, without any
-- flags set indicating that the observations or analysis is bad.
SELECT TOP 100
s.apogee_id,s.ra, s.dec, s.glon, s.glat,
s.vhelio_avg,s.vscatter,
a.teff,a.logg, a.metals, a.alphafe,
dbo.fApogeeAspcapFlagN(a.aspcapflag),
dbo.fApogeeStarFlagN(s.starflag)
FROM apogeeStar s
JOIN aspcapStar a on a.apstar_id = s.apstar_id
WHERE (a.aspcapflag & dbo.fApogeeAspcapFlag('STAR_BAD')) = 0
and a.teff > 0 and a.metals < -2
</textarea><textarea style="display:none" id="q_509946294">-- Get ASPCAP parameters for stars flagged as known cluster members:
-- In addition to selecting main survey targets, you can
-- select other objects according how they were selected. This is
-- an example of selecting objects chosen to be calibrator stars in
-- clusters with known metallicities (APOGEE_CALIB_CLUSTER).
SELECT TOP 100
s.apogee_id,s.ra, s.dec, s.glon, s.glat,
s.vhelio_avg,s.vscatter,
a.teff, a.teff_err, a.logg, a.logg_err, a.metals, a.metals_err,
a.alphafe, a.alphafe_err,
dbo.fApogeeAspcapFlagN(a.aspcapflag),
dbo.fApogeeStarFlagN(s.starflag)
FROM apogeeStar s
JOIN aspcapStar a on a.apstar_id = s.apstar_id
WHERE (a.aspcapflag & dbo.fApogeeAspcapFlag('STAR_BAD')) = 0 and
s.commiss = 0 and
(s.apogee_target2 & (dbo.fApogeeTarget2('APOGEE_CALIB_CLUSTER')) != 0)
</textarea><textarea style="display:none" id="q_1886714918">-- Get proper motions, JHK mag and errors, K-band extinction and radial
-- velocities, for stars with RVs > 300 km/s (with no BAD flags for RVs):
-- There is photometric data associated with each target, including proper
-- motions and other information. This example looks for such information
-- for larger (heliocentric) radial velocity stars. It restricts to objects
-- with good measured ASPCAP parameters. This requires joining the apogeeStar and
-- aspcapStar tables with the apogeeObject table, which has the target information.
SELECT TOP 100
star.apogee_id, star.ra, star.dec, star.glon, star.glat,
star.vhelio_avg, star.vscatter,
obj.j, obj.h, obj.k, obj.ak_targ, obj.ak_targ_method, obj.ak_wise,
aspcap.teff, aspcap.logg, aspcap.metals
FROM apogeeStar star
JOIN aspcapStar aspcap on aspcap.apstar_id = star.apstar_id
JOIN apogeeObject obj on aspcap.target_id = obj.target_id
WHERE (aspcap.aspcapflag & dbo.fApogeeAspcapFlag('STAR_BAD')) = 0 and aspcap.teff > 0
and (star.vhelio_avg > 300) and (star.starflag &
dbo.fApogeeStarFlag('SUSPECT_RV_COMBINATION')) = 0
and star.nvisits > 2 order by aspcap.apogee_id
</textarea><textarea style="display:none" id="q_214541362">-- Get ASPCAP parameters and targeting flags for all stars with 1 degree of a cluster center:
-- CASJobs allows search for objects near any particular RA and Dec. The
-- following example searches for ASPCAP parameters and targeting flags for
-- the stars observed near M13.
SELECT star.apstar_id,
star.apogee_id, star.ra, star.dec, star.glon, star.glat,
star.apogee_target1, star.apogee_target2,
aspcap.teff,aspcap.logg,aspcap.metals
FROM apogeeStar star
JOIN dbo.fGetNearbyApogeeStarEq(250.423458,36.461306,60) near on
star.apstar_id=near.apstar_id
JOIN aspcapStar aspcap on aspcap.apstar_id = star.apstar_id
</textarea><textarea style="display:none" id="q_114253696">
-- Get individual RVs from individual visits, the ASPCAP parameters for the combined
-- spectra for stars which have more than 6 visits:
-- Each star is visited several times, and in some case many times, in
-- order to build up signal-to-noise and to detect radial velocity
-- variations. The information about each visit to each star is in the
-- apogeeVisit table. One could join this table with apogeeStar on
-- apogee_id in order to literally find all visits to each star. However,
-- in this example we are interested in just finding those visits that
-- actually contributed to each combined spectrum. In this case, bad visits
-- are excluded and commissioning data and survey data are kept separate
-- (not combined). To find these stars, one may use the apogeeStarVisit
-- table in CAS, or the array visit_pk which exists for each star in the
-- allStar file. Alternatively, if you wanted to find all visits to a
-- particular star, one could replace in the code below apogeeStarVisit
-- with apogeeStarAllVisit and visit_pk with all_visit_pk.
SELECT top 100
visit.*, aspcap.teff, aspcap.logg, aspcap.metals
FROM apogeeVisit visit
JOIN apogeeStarVisit starvisit on visit.visit_id = starvisit.visit_id
JOIN aspcapStar aspcap on aspcap.apstar_id = starvisit.apstar_id
JOIN apogeeStar star on star.apstar_id = starvisit.apstar_id
WHERE (aspcap.aspcapflag & dbo.fApogeeAspcapFlag('STAR_BAD')) = 0 and aspcap.teff > 0
and (star.apogee_target1 & dbo.fApogeeTarget1('APOGEE_LONG')) > 0
and star.nvisits > 6
ORDER BY visit.apogee_id
</textarea><textarea style="display:none" id="q_286757891">-- Get APOGEE_IDs and SDSS/BOSS plate, mjd, fiberid for all stars that have both APOGEE and SEGUE spectra:
-- A small number of objects have been observed both in the optical with
-- the SDSS and/or BOSS spectrographs and in the infrared with the APOGEE
-- spectrograph. The examples below finds all matches between primary
-- SDSS/BOSS spectra and APOGEE stars with a 3 arcsec tolerance for such
-- cases (note that there are some cases where an entry in one catalog
-- matches multiple entries in the other).
SELECT TOP 50
specobj.plate as specobj_plate, specobj.mjd as specobj_mjd,
specobj.fiberid as specobj_fiberid,
specobj.ra as specobj_ra, specobj.dec as specobj_dec,
star.apstar_id, star.ra as star_ra, star.dec as star_dec
FROM apogeeStar AS star
CROSS APPLY dbo.fGetNearestSpecObjEq( star.ra, star.dec, 0.05) AS near
JOIN specobj ON near.specobjid=specobj.specobjid
</textarea><textarea style="display:none" id="q_251526975">-- Get SDSS ugriz photometry, errors and flags, ASPCAP parameters for the APOGEE stars with b > 60:
-- In addition to matching to the SDSS spectroscopy, you can also match to
-- the SDSS photometric imaging data. In this case, we only give an example
-- within CAS. To do this purely with flat files requires either
-- downloading the full photometric catalog (about 3 Tbytes) or the
-- "datasweep" files (about 300 Gbytes), both described in the imaging data
-- access documentation, and constructing an efficient flat-file method to
-- do the matching. For most purposes, CAS will be the right way to do this.
SELECT TOP 50
photoobj.run, photoobj.camcol, photoobj.field, photoobj.obj,
photoobj.psfmag_u, photoobj.psfmag_g, photoobj.psfmag_r,
photoobj.psfmag_i, photoobj.psfmag_z,
photoobj.ra as photoobj_ra, photoobj.dec as photoobj_dec,
star.apstar_id, star.ra as star_ra, star.dec as star_dec,
aspcap.teff, aspcap.metals, aspcap.logg
FROM apogeeStar AS star
CROSS APPLY dbo.fGetNearestObjEq( star.ra, star.dec, 0.05) AS near
JOIN photoobj ON near.objid=photoobj.objid
JOIN aspcapStar as aspcap ON star.apstar_id = aspcap.apstar_id
WHERE star.glat > 60. and aspcap.teff > 0
</textarea>
<textarea style="display:none" id="q_341160974">-- Find unique objects in an RA/Dec box.
-- PhotoPrimary is a view which selects only unique objects.
-- The full list of good detections including duplicates is in PhotoObj
-- A basic SELECT-FROM-WHERE query.
SELECT TOP 100 objID, -- Get the unique object ID,
field, ra, dec -- the field number, and coordinates
FROM PhotoPrimary -- From the photometric data
WHERE
ra > 185. and ra < 185.1 and dec > 15. and dec < 15.1 </textarea><textarea style="display:none" id="q_2088747594">-- Galaxies meeting two simple criteria.
-- Find all galaxies brighter than r magnitude 22, where the local
-- extinction is > 0.175. This is a simple query that uses a WHERE clause,
-- but now two conditions that must be met simultaneously.
SELECT TOP 10 objID
FROM Galaxy
WHERE
r < 22 -- r IS NOT deredenned
and extinction_r > 0.175 -- extinction more than 0.175
</textarea><textarea style="display:none" id="q_326961301">-- Find specific types of quasars using spectroscopy.
-- The easiest way to find quasars is by finding objects whose spectra have
-- been classified as quasars. This sample query searches the SpecObj
-- table for the IDs and redshifts of objects with the class column equal to 'QSO'
SELECT TOP 100 specObjID, z
FROM SpecObj
WHERE class = 'QSO' AND zWarning = 0
</textarea><textarea style="display:none" id="q_1559254220">-- Using the BETWEEN syntax.
-- Find all galaxies in a certain area of the sky that also meet other
-- criteria in their measured parameters. This query intriduces the
-- BETWEEN construct to specify a range of values.
SELECT TOP 100 objID, ra, dec, cModelMag_g
FROM Galaxy
WHERE ra BETWEEN 178 AND 180
AND dec < 0
AND cModelMag_g BETWEEN 18 AND 19
</textarea><textarea style="display:none" id="q_364596238">-- Using spatial unit vectors for coordinate cuts.
-- Find galaxies in a given area of the sky, using a coordinate cut
-- in the unit vector cx,cy,cz that corresponds to a specific RA range.
-- Another simple query that uses math in the WHERE clause.
--
-- NOTE: This query must be run in batch mode, i.e. using the Submit button
-- because it takes too long to execute in Quick mode.
SELECT TOP 100 colc_g, colc_r
FROM Galaxy
WHERE
(-0.466 * cx + 0.689 * cy>=0)
and (-0.385 * cx - 0.173 * cy <0)
</textarea><textarea style="display:none" id="q_1145250273">-- Find CVs using colors.
-- Search for Cataclysmic Variables and pre-CVs with White Dwarfs and
-- very late secondaries. Just uses some simple color cuts from Paula Szkody.
-- Another simple query that uses math in the WHERE clause
SELECT TOP 100 run,
camCol,
rerun,
field,
objID,
u, g, r, i, z,
ra, dec -- Just get some basic quantities
FROM PhotoPrimary -- From all primary detections, regardless of class
WHERE u - g < 0.4
and g - r < 0.7
and r - i > 0.4
and i - z > 0.4 -- that meet the color criteria
</textarea><textarea style="display:none" id="q_965086605">-- Getting a subsample of the data.
--
-- Uses the integer short object id (obj) - which is the least significant bits
-- of the long objID - and the '%' operator (remainder) to get every 1000th
-- object.
-- NOTE: THIS IS NOT A TRULY RANDOM SAMPLE!
SELECT TOP 100 u, g, r, i, z
FROM Galaxy with (nolock)
WHERE (objID%1000) = 1
AND (r between 18 and 21)
</textarea><textarea style="display:none" id="q_893526326">-- Low-z QSO candidates using color cuts.
-- from Gordon Richards.
-- Also a simple query with a long WHERE clause.
SELECT TOP 1000 g, run, rerun, camcol, field, objID
FROM
Galaxy
WHERE (
(g <= 22) and
(u-g >= -0.27) and (u-g < 0.71) and
(g-r >= -0.24) and (g-r < 0.35) and
(r-i >= -0.27) and (r-i < 0.57) and
(i-z >= -0.35) and (i-z < 0.70)
)</textarea><textarea style="display:none" id="q_1359629897">-- Get object velocities and errors.
-- This is also a simple query that uses a WHERE clause.
-- However, now we perform a more complex mathematical operation.
SELECT TOP 10
run, -- get a bunch of quantities
camCol,
field,
objID,
rowC, colC, rowV, colV, rowVErr, colVErr,
flags,
psfMag_u, psfMag_g, psfMag_r, psfMag_i, psfMag_z,
psfMagErr_u, psfMagErr_g, psfMagErr_r, psfMagErr_i, psfMagErr_z
FROM PhotoPrimary
WHERE ((rowv * rowv) / (rowvErr * rowvErr) +
(colv * colv) / (colvErr * colvErr) > 4)
-- where the velocities are reliable
</textarea><textarea style="display:none" id="q_2046520797">-- Finding galaxies by their emission lines:
--
-- SDSS-III handles searches by spectral lines differently than previous
-- releases. In addition, spectral lines for galaxies and stars are
-- identified through different processes. See the "Spectra of Red
-- Stars" sample query for an example of using stellar spectra.
--
-- Spectral lines for galaxies are calculated using the MPA-JHU
-- spectroscopic reanalysis (Tremonti et al. 2004; Brinchmann et al. 2004)
-- and are stored in the galSpecLine table. For more on how spectral lines
-- of galaxies are found, see the Galspec page of the sdss3.org website.
--
-- This query selects galaxy spectra with high internal reddening,
-- as measured by the standard Balmer decrement technique. It
-- makes use of the galSpec tables for the measurements of
-- galaxy lines. In this case we use galSpecLine, which has
-- emission line measurements.
SELECT
s.plate, s.fiberid, s.mjd, s.z, s.zwarning,
g.h_beta_flux, g.h_beta_flux_err,
g.h_alpha_flux, g.h_alpha_flux_err
FROM GalSpecLine AS g
JOIN dbo.SpecObj AS s ON s.specobjid = g.specobjid
WHERE
h_alpha_flux > h_alpha_flux_err*5
AND h_beta_flux > h_beta_flux_err*5
AND h_beta_flux_err > 0
AND h_alpha_flux > 10.*h_beta_flux
AND s.class = 'GALAXY'
AND s.zwarning = 0
</textarea><textarea style="display:none" id="q_1722069906">-- Moving objects consistent with an asteroid.
-- Also a simple query, but we introduce the 'as' syntax, which allows us to
-- name derived quantities in the result file.
--
-- NOTE: Since asteroids are rare objects in the SDSS data, this query will
-- take a long time to run without the "TOP 10" and should be executed
-- in batch mode (with the Submit button).
SELECT TOP 10
objID,
sqrt( power(rowv,2) + power(colv, 2) ) as velocity
FROM PhotoObj
WHERE
(power(rowv,2) + power(colv, 2)) between 50 and 1000
</textarea><textarea style="display:none" id="q_504267227">-- Find quasars in imaging data.
-- as specified by Xiaohui Fan et.al.
-- A rather straightforward query, just with many conditions.
SELECT TOP 100 run,
camCol,
rerun,
field,
objID,
u, g, r, i, z,
ra, dec
FROM Star -- or Galaxy
WHERE ( u - g > 2.0 or u > 22.3 )
and ( i < 19 )
and ( i > 0 )
and ( g - r > 1.0 )
and ( r - i <
(0.08 + 0.42 * (g - r - 0.96) )
or g - r > 2.26 )
and ( i - z < 0.25 )
</textarea><textarea style="display:none" id="q_273521898">-- Using object counting and logic in a query.
-- Find all objects similar to the colors of a quasar at 5.5<redshift<6.5.
-- An area restriction is added so the query will run in the Quick queue.
SELECT count(*) as 'total',
sum( case when (Type=3) then 1 else 0 end) as 'Galaxies',
sum( case when (Type=6) then 1 else 0 end) as 'Stars',
sum( case when (Type not in (3,6)) then 1 else 0 end) as 'Other'
FROM PhotoPrimary -- for each object
WHERE
(ra between 180 and 190) and (dec between -5 and 5)
and (( u - g > 2.0) or (u > 22.3) ) -- apply the quasar color cut.
and ( i between 0 and 19 )
and ( g - r > 1.0 )
and ( (r - i < 0.08 + 0.42 * (g - r - 0.96)) or (g - r > 2.26 ) )
and ( i - z < 0.25 )
</textarea><textarea style="display:none" id="q_1145880200">-- Find galaxies that are blended with a star.
-- Output the deblended galaxy magnitudes.
-- This query introduces the use of multiple tables or views. You can assign
-- nicknames to tables as in the FROM clause below. Since you are using
-- multiple tables, you must specify which table each quantity in the SELECT
-- clause comes from. The query illustrates the JOIN syntax between
-- the two tables, which requires that a common quantity that is present in
-- both tables be equal, in this case their common parent object.
SELECT top 1000 G.ObjID, G.u, G.g, G.r, G.i, G.z
FROM Galaxy G -- compare Galaxy and Star
JOIN Star S ON G.parentID = S.parentID -- using the same parent
WHERE
G.parentID > 0 -- if the galaxy has a "parent", this object was deblended
</textarea><textarea style="display:none" id="q_1019525219">-- Stars selected using Field criteria.
-- Give me the PSF colors of all stars brighter than g=20 that have PSP_STATUS = 2.
-- Another simple multi-table query.
SELECT TOP 1000
s.psfMag_g, -- or whatever you want from each object
s.run,
s.camCol,
s.rerun,
s.field
FROM Star s
JOIN Field f ON s.fieldID = f.fieldID
WHERE
s.psfMag_g < 20
and f.pspStatus = 2
</textarea><textarea style="display:none" id="q_891488825">-- Objects selected by cuts on three tables.
-- Find the parameters for all objects in a selected field with
-- desired PSF width and range of columns.
-- Now we are using three tables, but it is still a simple query.
SELECT TOP 1000
f.run,
f.rerun,
f.camCol,
f.field,
p.objID,
p.ra,
p.dec,
p.Rowc,
p.Colc,
p.u,
p.modelMagErr_u ,
p.g,
p.modelMagErr_g,
p.r,
p.modelMagErr_r,
p.petroMag_r - p.extinction_r,
p.petroMagErr_r,
p.i,
p.modelMagErr_i,
p.z,
f.psfWidth_r,
r.stripe,
r.strip
FROM
photoObj p
JOIN field f ON f.fieldid = p.fieldid
JOIN run r ON r.run=f.run
WHERE
f.psfWidth_r > 1.2
and p.colc > 400.0
</textarea><textarea style="display:none" id="q_1456890876">-- Find all objects within 30 arcseconds of one another
-- that have very similar colors: that is where the color ratios
-- u-g, g-r, r-I are less than 0.05m. This query introduces the
-- Neighbors table, which is a pre-computed list of the nearest
-- neighbors of each object within 30 arcseconds.
SELECT TOP 10 P.ObjID as objid1, L.ObjID as objid2, N.distance
FROM PhotoPrimary P -- P is the primary object
JOIN Neighbors N ON P.ObjID = N.ObjID -- N is the neighbor link
JOIN PhotoPrimary L ON L.ObjID = N.NeighborObjID -- L is the lens candidate of P
WHERE
P.ObjID < L. ObjID -- avoid duplicates
and abs((P.u-P.g)-(L.u-L.g))<0.05 -- L and P have similar spectra
and abs((P.g-P.r)-(L.g-L.r))<0.05
and abs((P.r-P.i)-(L.r-L.i))<0.05
and abs((P.i-P.z)-(L.i-L.z))<0.05
</textarea><textarea style="display:none" id="q_1683900573">-- Find stars with multiple measurements with magnitude variations >0.1.
-- Note that this runs very slowly unless explicit workarounds are included
-- for some SQLServer Optimizer bugs, which are NOT included here
SELECT TOP 100
S1.objID as objID1, S2.objID as ObjID2 -- select object IDs of star and its pair
FROM Star as S1, -- the primary star
photoObj as S2, -- the second observation of the star
neighbors as N -- the neighbor record
WHERE S1.objID = N.objID -- insist the stars are neighbors
and S2.objID = N.neighborObjID -- using precomputed neighbors table
and distance < 0.5/60 -- distance is 0.5 arc second or less
and S1.run != S2.run -- observations are two different runs
and S2.type = dbo.fPhotoType('Star') -- S2 is indeed a star
and S1.u between 1 and 27 -- S1 magnitudes are reasonable
and S1.g between 1 and 27
and S1.r between 1 and 27
and S1.i between 1 and 27
and S1.z between 1 and 27
and S2.u between 1 and 27 -- S2 magnitudes are reasonable.
and S2.g between 1 and 27
and S2.r between 1 and 27
and S2.i between 1 and 27
and S2.z between 1 and 27
and ( -- and one of the colors is different.
abs(S1.u-S2.u) > .1 + (abs(S1.Err_u) + abs(S2.Err_u))
or abs(S1.g-S2.g) > .1 + (abs(S1.Err_g) + abs(S2.Err_g))
or abs(S1.r-S2.r) > .1 + (abs(S1.Err_r) + abs(S2.Err_r))
or abs(S1.i-S2.i) > .1 + (abs(S1.Err_i) + abs(S2.Err_i))
or abs(S1.z-S2.z) > .1 + (abs(S1.Err_z) + abs(S2.Err_z))
)
</textarea><textarea style="display:none" id="q_538248463">-- Checking for errors using flags.
-- Another useful query is to see if the errors on moving (or
-- apparently moving) objects are correct. For example, it used to be that
-- some known QSOs were being flagged as moving objects. One way to look for
-- such objects is to compare the velocity to the error in velocity and see if
-- the "OBJECT1_MOVED" or "OBJECT2_BAD_MOVING_FIT" is set.
-- This query introduces bitwise logic for flags, and uses the 'as' syntax to
-- make the query more readable. Note that if a flag is not set, the value
-- will be zero. If you want to ensure multiple flags are not set, you can
-- either check that each individually is zero, or that their sum is zero.
-- (From Gordon Richards)
--
-- NOTE: A caveat about using functons (like fPhotoFlags) is that if your
-- query is selecting a very large number of rows (e.g. hundreds of
-- thousands or millions) then it's that many function calls, and
-- this will slow down the query execution significantly. In that
-- case, you should replace the function call with its equivalent
-- binary bitmask, e.g. if you run the query (with Quick button)
-- SELECT (dbo.fPhotoFlags('MOVED') + dbo.fPhotoFlags('BAD_MOVING_FIT'))
-- you will get the value 36507222016, which you can substitute in
-- first line of the WHERE clause below as:
-- (flags & 36507222016) > 0
-- to avoid zillions of function calls.
SELECT TOP 1000
run,
rerun,
camcol,
field,
objID,
ra, dec,
rowv, colv,
rowvErr, colvErr,
i,
(flags & dbo.fPhotoFlags('MOVED')) as MOVED,
(flags & dbo.fPhotoFlags('BAD_MOVING_FIT')) as BAD_MOVING_FIT
FROM Galaxy
WHERE
(flags & (dbo.fPhotoFlags('MOVED') + dbo.fPhotoFlags('BAD_MOVING_FIT'))) > 0
and (rowv * rowv + colv * colv) >=
(rowvErr * rowvErr + colvErr * colvErr)
</textarea><textarea style="display:none" id="q_2107503000">-- Elliptical galaxies based on model fits.
-- Find all galaxies with a deVaucouleours profile and the
-- photometric colors consistent with an elliptical galaxy.
-- This query has many conditions, and also shows more of the
-- bitwise logic necessary for dealing with flags.
SELECT TOP 100 ObjID
FROM Galaxy as G
WHERE
G.lnlDev_r > G.lnlExp_r + 0.1
-- the likelihood of the deVaucouleours profile fit is 10% greater than the likelihood of the exponential fit
and G.lnlExp_r > -999
-- and the likelihoods are actually meaningful
and (G.flags & (dbo.fPhotoFlags('BINNED1') + dbo.fPhotoFlags('BINNED2') + dbo.fPhotoFlags('BINNED4'))) > 0
--and it is detected from at least one of the binned images ???
and (G.flags & ( dbo.fPhotoFlags('BLENDED') + dbo.fPhotoFlags('NODEBLEND') + dbo.fPhotoFlags('CHILD'))) != dbo.fPhotoFlags('BLENDED')
--and, if it is blended, it is either a child or not deblended further ??
and (G.flags & (dbo.fPhotoFlags('EDGE') + dbo.fPhotoFlags('SATURATED'))) = 0
-- and it is not near a ccd edge or saturated, where measurements may be bad
and G.petroMag_i > 17.5
-- and it is fainter than 17.5 in i-band
and (G.petroMag_r > 15.5 or G.petror50_r > 2)
and (G.petroMag_r > 0 and G.g > 0 and G.r > 0 and G.i > 0)
and ( (G.petroMag_r - G.extinction_r) < 19.2
and (G.petroMag_r - G.extinction_r <
(13.1 + (7/3)*(G.g - G.r) + 4 *(G.r - G.i) - 4 * 0.18 ) )
and ( (G.r - G.i - (G.g - G.r)/4 - 0.18) < 0.2 )
and ( (G.r - G.i - (G.g - G.r)/4 - 0.18) > -0.2 ) )
or ( (G.petroMag_r - G.extinction_r < 19.5)
and ( (G.r - G.i - (G.g - G.r)/4 - 0.18) >
(0.45 - 4*(G.g - G.r) ) )
and ( (G.g - G.r) > (1.35 + 0.25 *(G.r - G.i) ) ) )
-- and many constraints on colors and mags are met to make it have
-- elliptical-type colors.
</textarea><textarea style="display:none" id="q_1724772452">-- Galaxies with bluer centers.
-- by Michael Strauss. For all galaxies
-- with r_Petro < 18, not saturated, not bright, and not edge, give me those
-- with centers appreciably bluer than their outer parts, i.e., define the
-- center color as: u_psf - g_psf and define the outer color as: u_model -
-- g_model; give me all objs which have (u_model - g_model) - (u_psf - g_psf)
-- < -0.4
-- Another flags-based query.
SELECT TOP 1000
colc_u, colc_g, objID
FROM Galaxy
WHERE
( Flags & (dbo.fPhotoFlags('SATURATED') +
dbo.fPhotoFlags('BRIGHT') +
dbo.fPhotoFlags('EDGE')) ) = 0
and petrorad_r < 18
and ((colc_u - colc_g) - (psfMag_u - psfMag_g)) < -0.4</textarea><textarea style="display:none" id="q_34323696">-- Diameter-limited sample of galaxies
-- from James Annis.
-- Another query that makes extensive use of photo flags to get a sample
-- of galaxies within a size range as specified by their i-band Petrosian
-- radius.
SELECT TOP 100
run,
camCol,
rerun,
field,
objID,
ra,
dec
FROM Galaxy
WHERE ( flags & (dbo.fPhotoFlags('BINNED1')
+ dbo.fPhotoFlags('BINNED2')
+ dbo.fPhotoFlags('BINNED4')) ) > 0
and ( flags & (dbo.fPhotoFlags('BLENDED')
+ dbo.fPhotoFlags('NODEBLEND')
+ dbo.fPhotoFlags('CHILD')) ) != dbo.fPhotoFlags('BLENDED')
and ( ( (flags & dbo.fPhotoFlags('NOPETRO') = 0)
and petrorad_i > 15)
or ( (flags & dbo.fPhotoFlags('NOPETRO') > 0)
and petrorad_i > 7.5)
or ( (flags & dbo.fPhotoFlags('TOO_LARGE') > 0)
and petrorad_i > 2.5)
or
( (flags & dbo.fPhotoFlags('SATURATED') = 0)
and petrorad_i > 17.5) )
</textarea><textarea style="display:none" id="q_357369514">-- Extremely red galaxies.
-- from James Annis.
-- Similar to the diameter limited sample query but selects galaxies that
-- are red (i-z color greater than a certain threshold).
SELECT TOP 1000
g.run,
g.camCol,
g.rerun,
g.field,
g.objID,
g.ra, g.dec
FROM Field f, Galaxy g
WHERE
g.fieldID = f.fieldID
and ( g.flags & (dbo.fPhotoFlags('BINNED1')
+ dbo.fPhotoFlags('BINNED2')
+ dbo.fPhotoFlags('BINNED4')) ) > 0
and ( g.flags & (dbo.fPhotoFlags('BLENDED')
+ dbo.fPhotoFlags('NODEBLEND')
+ dbo.fPhotoFlags('CHILD')) ) != dbo.fPhotoFlags('BLENDED')
and ( g.flags & (dbo.fPhotoFlags('COSMIC_RAY')
+ dbo.fPhotoFlags('INTERP')) ) = 0
and f.psfWidth_r < 1.5
and (g.i - g.z > 1.0 )
</textarea><textarea style="display:none" id="q_2085753961">-- A version of the LRG sample.
-- by James Annis.
-- Another query with many conditions and flag tests that selects Luminous
-- Red Galaxies (LRGs).
SELECT TOP 100
run,
camCol,
rerun,
field,
objID,
ra,
dec
FROM Galaxy
WHERE ( ( flags & (dbo.fPhotoFlags('BINNED1')
+ dbo.fPhotoFlags('BINNED2')
+ dbo.fPhotoFlags('BINNED4')) ) > 0
and ( flags & (dbo.fPhotoFlags('BLENDED')
+ dbo.fPhotoFlags('NODEBLEND')
+ dbo.fPhotoFlags('CHILD')) ) != dbo.fPhotoFlags('BLENDED')
and ( flags & (dbo.fPhotoFlags('EDGE')
+ dbo.fPhotoFlags('SATURATED')) ) = 0
and petroMag_i > 17.5
and (petroMag_r > 15.5 or petror50_r > 2)
and (petroMag_r > 0 and g > 0 and r > 0 and i > 0)
and ( (petroMag_r-extinction_r) < 19.2
and (petroMag_r - extinction_r <
(13.1 + (7/3) * (dered_g - dered_r) + 4 * (dered_r - dered_i) - 4 * 0.18) )
and ( (dered_r - dered_i - (dered_g - dered_r)/4 - 0.18) < 0.2)
and ( (dered_r - dered_i - (dered_g - dered_r)/4 - 0.18) > -0.2)
--dered_ quantities already include extinction
and ( (petroMag_r - extinction_r +
2.5 * LOG10(2 * 3.1415 * petror50_r * petror50_r)) < 24.2) )
or ( (petroMag_r - extinction_r < 19.5)
and ( (dered_r - dered_i - (dered_g - dered_r)/4 - 0.18) > (0.45 - 4 * (dered_g - dered_r)) )
and ( (dered_g - dered_r) > (1.35 + 0.25 * (dered_r - dered_i)) ) )
and ( (petroMag_r - extinction_r +
2.5 * LOG10(2 * 3.1415 * petror50_r * petror50_r) ) < 23.3 ) )
</textarea><textarea style="display:none" id="q_1598688566">-- Spectra of Red Stars
--
-- SDSS-III handles searches by spectral lines differently than previous
-- releases. In addition, spectral lines for galaxies and stars are
-- identified through different processes. See the "Galaxies with
-- Emission Lines" sample query for an example of using galaxy spectra.
--
-- Spectral lines for stars are calculated using the SEGUE Stellar Parameter
-- Pipeline (SSPP; Lee et al. 2008) and are stored in the sppLines
-- table. For more on how spectral lines of stars are found, see
-- the SSPP page of the sdss3.org website.
-- This query selects red stars (spectral type K), with large
-- CaII triplet eq widths, with low errors on the CaII triplet
-- equivalent widths.
SELECT
sl.plate,sl.mjd,sl.fiber,
sl.caIIKside,sl.caIIKerr,sl.caIIKmask,
sp.fehadop,sp.fehadopunc,sp.fehadopn,
sp.loggadopn,sp.loggadopunc
FROM sppLines AS sl
JOIN sppParams AS sp ON sl.specobjid = sp.specobjid
WHERE
fehadop < -3.5
AND fehadopunc between 0.01
and 0.5 and fehadopn > 3
</textarea><textarea style="display:none" id="q_1031426103">-- Galaxy counts on HTM grid.
--
-- Create a count of galaxies for each of the Hierarchical Triangular Mesh (HTM) triangles.
-- Galaxies should satisfy a certain color cut like 0.7u-0.5g-0.2i<1.25 && r<21.75, output
-- it in a form adequate for visualization.
SELECT (htmID / power(2,24)) as htm_8 ,
-- group by 8-deep HTMID (rshift HTM by 12)
avg(ra) as ra,
avg(dec) as [dec],
count(*) as pop -- return center point and count for display
FROM Galaxy -- only look at galaxies
WHERE
-- RA/dec cut added to make query run in Quick mode
(ra between 180 and 181 and dec between -1 and 1) and
(0.7*u - 0.5*g - 0.2*i) < 1.25 -- meeting this color cut
and r < 21.75 -- brighter than 21.75 magnitude in red band.
group by (htmID /power(2,24)) -- group into 8-deep HTM buckets.
</textarea><textarea style="display:none" id="q_907308906">-- Binary Stars Colors.
--
-- Find binary stars with specific colors.
-- At least one of them should have the colors (meets Paul Szkody's color cut) of a white dwarf.
SELECT TOP 100 s1.objID as s1, s2.objID as s2
FROM Star S1 -- S1 is the white dwarf
JOIN Neighbors N ON S1.objID = N. objID -- N is the precomputed neighbors link
JOIN Star S2 ON S2.objID = N.NeighborObjID -- S2 is the second star
WHERE
N.neighborType = dbo.fPhotoType('Star') -- and S2 is a star
and N.distance < .05 -- the 3 arcsecond test
and ((S1.u - S1.g) < 0.4 ) -- and S1 meets the color cut for
and (S1.g - S1.r) < 0.7 -- white dwarfs.
and (S1.r - S1.i) > 0.4
and (S1.i - S1.z) > 0.4
</textarea><textarea style="display:none" id="q_1246974053">-- Galaxies unsaturated near (given) coordinates.
--
-- Find galaxies without saturated pixels within 1' of a given point.
-- ra=185.0, dec=-0.5. This query uses a function fGetNearbyObjEq,
-- which takes 3 arguments (ra,dec, distance in arcmin); this function uses
-- the Neighbors table. The Neighbors table and the Galaxy table have in
-- common the objID, so we have to select objects from both where the objIDs
-- are the same. The output of the function is a table with the Galaxy Object
-- ID and distance in arcmin from the input. This query introduces the use of
-- a JOIN to combine table contents. Also, we use the 'ORDER BY' syntax,
-- which will sort the output.
SELECT TOP 100 G.objID, GN.distance
FROM Galaxy AS G
JOIN dbo.fGetNearbyObjEq(185.,-0.5, 1) AS GN -- this function outputs a table, so we have to do a join
ON G.objID = GN.objID -- get objects from temporary neighbors table GN with desired ObjID
WHERE
(G.flags & dbo.fPhotoFlags('saturated')) = 0 -- and the object is not saturated. f.PhotoFlags is a function that interprets the flag bits.
ORDER BY distance -- sort these by distance
</textarea><textarea style="display:none" id="q_1446002135">-- Search near BCG galaxies.
--
-- For each galaxy in the BCG data set (brightest cluster galaxy),
-- in 160<right ascension<170, -25<declination<35 count the number of
-- galaxies within 30" of it that have a photoz within 0.05
-- of that galaxy.
-- This query has a very complex WHERE clause.
SELECT TOP 1000 G.objID, COUNT(N.NeighborObjID) AS pop
FROM Galaxy AS G -- first gravitational lens candidate
JOIN Neighbors AS N ON G.objID = N.objID -- precomputed list of neighbors
JOIN Galaxy AS U ON U.objID = N.neighborObjID -- a neighbor galaxy of G
JOIN photoZ AS Gpz ON G.objID = Gpz.objID -- photoZ of G.
JOIN photoZ AS Npz ON U.objID = Npz.objID -- neighbor photoZ
WHERE
G.ra BETWEEN 160 AND 170
AND G.dec BETWEEN -5 AND 5
AND N.objID < N.neighborObjID -- 30 arcseconds of one another.
AND ABS(Gpz.Z - Npz.Z) < 0.05 -- restrict the photoZ differences
AND (G.flags & (dbo.fPhotoFlags('BINNED1') + dbo.fPhotoFlags('BINNED2') + dbo.fPhotoFlags('BINNED4'))) > 0
--and it is detected from at least one of the binned images
AND (G.flags & ( dbo.fPhotoFlags('BLENDED') + dbo.fPhotoFlags('NODEBLEND') + dbo.fPhotoFlags('CHILD'))) != dbo.fPhotoFlags('BLENDED')
--and, if it is blended, it is either a child or not deblended further ??
AND (G.flags & (dbo.fPhotoFlags('EDGE') + dbo.fPhotoFlags('SATURATED'))) = 0
-- and it is not near a ccd edge or saturated, where measurements may be bad
-- and apply color cut for a BCG courtesy of James Annis of Fermilab
AND G.petroMag_i > 17.5
AND (G.petroMag_r > 15.5 or G.petror50_r > 2)
AND (G.petroMag_r < 30 AND G.g < 30 AND G.r < 30 AND G.i < 30)
AND (G.r < 19.2
AND ( 1=1 or -- huh?
(G.r < (13.1 + (7/3)*(G.g - G.r) +
-- deRed_r < 13.1 + 0.7 / 0.3 * deRed_gr
4 *(G.r - G.i - 0.18 ))
-- 1.2 / 0.3 * deRed_ri
AND (( G.r - G.i - (G.g - G.r)/4 - 0.18) BETWEEN -0.2 AND 0.2 )
AND ((G.r +
-- petSB - deRed_r + 2.5 log10(2Pi*petror50^2)
2.5 * LOG( 2 * 3.1415 * G.petror50_r * G.petror50_r )) < 24.2 )
)
or
( (G.r < 19.5 )
AND (( G.r - G.i -(G.g - G.r)/4 -.18) >
-- - deRed_gr/4 - 0.18
-- cperp = deRed_ri
(0.45 - 4*( G.g - G.r)))
-- 0.45 - deRed_gr/0.25
AND ((G.g - G.r) > ( 1.35 + 0.25 *(G.r - G.i)))
AND ((G.r +
-- petSB - deRed_r + 2.5 log10(2Pi*petror50^2)
2.5 * LOG( 2 * 3.1415 * G.petror50_r * G.petror50_r )) < 23.3 )
)) )
GROUP BY G.objID
</textarea><textarea style="display:none" id="q_45055564">-- The detectionIndex table contains all detections of a given physical object,
-- which is uniquely identified by the "thingid". In order to extract photometry,
-- you need a join with the PhotoObjAll table, using the objid.
-- There is also a flag field called isPrimary, which is 1 for the object that
-- is found on a primary polygon/field, all the other detections have 0 in this field.
-- Here is a compound query to find all time series around a certain object with a thingid= 97423000
SELECT
LTRIM(STR(mjd_r,20,2)) AS MJD,
dbo.fSDSS(p.objId) AS ID,
modelMag_g, modelMagErr_g,
modelMag_r, modelMagErr_r,
modelMag_i, modelMagErr_i, p.ra, p.dec
INTO #list
FROM detectionindex d
JOIN PhotoObjAll p ON d.objid=p.objid
JOIN Field f ON p.fieldid=f.fieldid
WHERE d.thingid=97423000
ORDER BY 1
GO
--
-- Now find objects near each of the detections
--
SELECT a.*, b.*
FROM #list a
CROSS APPLY dbo.fGetNearbyObjEq(a.ra, a.dec, 0.1) b
</textarea><textarea style="display:none" id="q_1674347198">-- The APOGEE survey is conducted along a number of different lines of sight,
-- each referred to as as a "field" or "location" (interchangeably). Each
-- field has a name and an id number (LOCATION_ID). The stars in each field
-- are observed multiple times on multiple visits, on different MJDs. These
-- may involve one or more physical plug plates.
-- To find all the plate visits, one can search as follows (for LOCATION_ID
-- 4105):
SELECT plate, mjd FROM apogeePlate WHERE location_id=4105
-- The same field can be searched by its name (in this case 'M13'):
SELECT plate, mjd FROM apogeePlate WHERE name = 'M13'
</textarea><textarea style="display:none" id="q_29000041">-- Get ASPCAP parameters and errors for all stars that were targeted as part
-- of the main APOGEE survey:
-- The stellar parameters are available for all stars that had ASPCAP run
-- on them. However, this includes some spectra known to be bad as well as
-- stars targeted as part of ancillary programs of various
-- sorts. Restricting to the good, main survey targets requires checking on
-- target and catalog flags, as in the examples below:
SELECT TOP 100
s.apogee_id,s.ra, s.dec, s.glon, s.glat,
s.vhelio_avg,s.vscatter,
a.teff, a.teff_err, a.logg, a.logg_err, a.metals, a.metals_err,
a.alphafe, a.alphafe_err,
dbo.fApogeeAspcapFlagN(a.aspcapflag),
dbo.fApogeeStarFlagN(s.starflag)
FROM apogeeStar s
JOIN aspcapStar a on a.apstar_id = s.apstar_id
WHERE (a.aspcapflag & dbo.fApogeeAspcapFlag('STAR_BAD')) = 0 and
s.commiss = 0 and
(s.apogee_target1 &
(dbo.fApogeeTarget1('APOGEE_SHORT')+
dbo.fApogeeTarget1('APOGEE_INTERMEDIATE')+
dbo.fApogeeTarget1('APOGEE_LONG'))) != 0
</textarea><textarea style="display:none" id="q_1193882752">-- Get parameters for all stars with [Fe/H] < -2 with no BAD FLAGS set:
-- You can also select a subset of the stars based on their
-- properties. This example finds a set of metal-poor stars, without any
-- flags set indicating that the observations or analysis is bad.
SELECT TOP 100
s.apogee_id,s.ra, s.dec, s.glon, s.glat,
s.vhelio_avg,s.vscatter,
a.teff,a.logg, a.metals, a.alphafe,
dbo.fApogeeAspcapFlagN(a.aspcapflag),
dbo.fApogeeStarFlagN(s.starflag)
FROM apogeeStar s
JOIN aspcapStar a on a.apstar_id = s.apstar_id
WHERE (a.aspcapflag & dbo.fApogeeAspcapFlag('STAR_BAD')) = 0
and a.teff > 0 and a.metals < -2
</textarea><textarea style="display:none" id="q_1745805745">-- Get ASPCAP parameters for stars flagged as known cluster members:
-- In addition to selecting main survey targets, you can
-- select other objects according how they were selected. This is
-- an example of selecting objects chosen to be calibrator stars in
-- clusters with known metallicities (APOGEE_CALIB_CLUSTER).
SELECT TOP 100
s.apogee_id,s.ra, s.dec, s.glon, s.glat,
s.vhelio_avg,s.vscatter,
a.teff, a.teff_err, a.logg, a.logg_err, a.metals, a.metals_err,
a.alphafe, a.alphafe_err,
dbo.fApogeeAspcapFlagN(a.aspcapflag),
dbo.fApogeeStarFlagN(s.starflag)
FROM apogeeStar s
JOIN aspcapStar a on a.apstar_id = s.apstar_id
WHERE (a.aspcapflag & dbo.fApogeeAspcapFlag('STAR_BAD')) = 0 and
s.commiss = 0 and
(s.apogee_target2 & (dbo.fApogeeTarget2('APOGEE_CALIB_CLUSTER')) != 0)
</textarea><textarea style="display:none" id="q_111582421">-- Get proper motions, JHK mag and errors, K-band extinction and radial
-- velocities, for stars with RVs > 300 km/s (with no BAD flags for RVs):
-- There is photometric data associated with each target, including proper
-- motions and other information. This example looks for such information
-- for larger (heliocentric) radial velocity stars. It restricts to objects
-- with good measured ASPCAP parameters. This requires joining the apogeeStar and
-- aspcapStar tables with the apogeeObject table, which has the target information.
SELECT TOP 100
star.apogee_id, star.ra, star.dec, star.glon, star.glat,
star.vhelio_avg, star.vscatter,
obj.j, obj.h, obj.k, obj.ak_targ, obj.ak_targ_method, obj.ak_wise,
aspcap.teff, aspcap.logg, aspcap.metals
FROM apogeeStar star
JOIN aspcapStar aspcap on aspcap.apstar_id = star.apstar_id
JOIN apogeeObject obj on aspcap.target_id = obj.target_id
WHERE (aspcap.aspcapflag & dbo.fApogeeAspcapFlag('STAR_BAD')) = 0 and aspcap.teff > 0
and (star.vhelio_avg > 300) and (star.starflag &
dbo.fApogeeStarFlag('SUSPECT_RV_COMBINATION')) = 0
and star.nvisits > 2 order by aspcap.apogee_id
</textarea><textarea style="display:none" id="q_1441850959">-- Get ASPCAP parameters and targeting flags for all stars with 1 degree of a cluster center:
-- CASJobs allows search for objects near any particular RA and Dec. The
-- following example searches for ASPCAP parameters and targeting flags for
-- the stars observed near M13.
SELECT star.apstar_id,
star.apogee_id, star.ra, star.dec, star.glon, star.glat,
star.apogee_target1, star.apogee_target2,
aspcap.teff,aspcap.logg,aspcap.metals
FROM apogeeStar star
JOIN dbo.fGetNearbyApogeeStarEq(250.423458,36.461306,60) near on
star.apstar_id=near.apstar_id
JOIN aspcapStar aspcap on aspcap.apstar_id = star.apstar_id
</textarea><textarea style="display:none" id="q_988146083">
-- Get individual RVs from individual visits, the ASPCAP parameters for the combined
-- spectra for stars which have more than 6 visits:
-- Each star is visited several times, and in some case many times, in
-- order to build up signal-to-noise and to detect radial velocity
-- variations. The information about each visit to each star is in the
-- apogeeVisit table. One could join this table with apogeeStar on
-- apogee_id in order to literally find all visits to each star. However,
-- in this example we are interested in just finding those visits that
-- actually contributed to each combined spectrum. In this case, bad visits
-- are excluded and commissioning data and survey data are kept separate
-- (not combined). To find these stars, one may use the apogeeStarVisit
-- table in CAS, or the array visit_pk which exists for each star in the
-- allStar file. Alternatively, if you wanted to find all visits to a
-- particular star, one could replace in the code below apogeeStarVisit
-- with apogeeStarAllVisit and visit_pk with all_visit_pk.
SELECT top 100
visit.*, aspcap.teff, aspcap.logg, aspcap.metals
FROM apogeeVisit visit
JOIN apogeeStarVisit starvisit on visit.visit_id = starvisit.visit_id
JOIN aspcapStar aspcap on aspcap.apstar_id = starvisit.apstar_id
JOIN apogeeStar star on star.apstar_id = starvisit.apstar_id
WHERE (aspcap.aspcapflag & dbo.fApogeeAspcapFlag('STAR_BAD')) = 0 and aspcap.teff > 0
and (star.apogee_target1 & dbo.fApogeeTarget1('APOGEE_LONG')) > 0
and star.nvisits > 6
ORDER BY visit.apogee_id
</textarea><textarea style="display:none" id="q_197092168">-- Get APOGEE_IDs and SDSS/BOSS plate, mjd, fiberid for all stars that have both APOGEE and SEGUE spectra:
-- A small number of objects have been observed both in the optical with
-- the SDSS and/or BOSS spectrographs and in the infrared with the APOGEE
-- spectrograph. The examples below finds all matches between primary
-- SDSS/BOSS spectra and APOGEE stars with a 3 arcsec tolerance for such
-- cases (note that there are some cases where an entry in one catalog
-- matches multiple entries in the other).
SELECT TOP 50
specobj.plate as specobj_plate, specobj.mjd as specobj_mjd,
specobj.fiberid as specobj_fiberid,
specobj.ra as specobj_ra, specobj.dec as specobj_dec,
star.apstar_id, star.ra as star_ra, star.dec as star_dec
FROM apogeeStar AS star
CROSS APPLY dbo.fGetNearestSpecObjEq( star.ra, star.dec, 0.05) AS near
JOIN specobj ON near.specobjid=specobj.specobjid
</textarea><textarea style="display:none" id="q_871745526">-- Get SDSS ugriz photometry, errors and flags, ASPCAP parameters for the APOGEE stars with b > 60:
-- In addition to matching to the SDSS spectroscopy, you can also match to
-- the SDSS photometric imaging data. In this case, we only give an example
-- within CAS. To do this purely with flat files requires either
-- downloading the full photometric catalog (about 3 Tbytes) or the
-- "datasweep" files (about 300 Gbytes), both described in the imaging data
-- access documentation, and constructing an efficient flat-file method to
-- do the matching. For most purposes, CAS will be the right way to do this.
SELECT TOP 50
photoobj.run, photoobj.camcol, photoobj.field, photoobj.obj,
photoobj.psfmag_u, photoobj.psfmag_g, photoobj.psfmag_r,
photoobj.psfmag_i, photoobj.psfmag_z,
photoobj.ra as photoobj_ra, photoobj.dec as photoobj_dec,
star.apstar_id, star.ra as star_ra, star.dec as star_dec,
aspcap.teff, aspcap.metals, aspcap.logg
FROM apogeeStar AS star
CROSS APPLY dbo.fGetNearestObjEq( star.ra, star.dec, 0.05) AS near
JOIN photoobj ON near.objid=photoobj.objid
JOIN aspcapStar as aspcap ON star.apstar_id = aspcap.apstar_id
WHERE star.glat > 60. and aspcap.teff > 0
</textarea>
<textarea style="display:none" id="q_658663612">-- Basic_SELECT_FROM_WHERE
-- Find objects in a particular field.
SELECT objID,
field, ra, dec -- Get the unique object ID, field number, and coords
FROM PhotoObj -- From the photometric data
WHERE fieldID = 587722951961673728 -- that is in a specific field
</textarea><textarea style="display:none" id="q_2046242728">-- Galaxies meeting two simple criteria.
-- Find all galaxies brighter than r magnitude 17, where the local
-- extinction is > 0.275. This is a simple query that uses a WHERE clause,
-- but now two conditions that must be met simultaneously.
--
-- Finds 6604 galaxies in under 10 mins on DR2, but beware that increasing
-- the limiting r magnitude will significantly add to the execution time.
SELECT objID
FROM Galaxy
WHERE
r < 17 -- r IS NOT deredenned
and extinction_r > 0.275 -- extinction more than 0.175
</textarea><textarea style="display:none" id="q_100466571">-- Find all objects with unclassified spectra.
-- A simple SELECT-FROM-WHERE query, using a function
--
-- On DR2, returns 3109 rows in 20 sec.
SELECT specObjID
FROM SpecObj
WHERE SpecClass = dbo.fSpecClass('UNKNOWN')</textarea><textarea style="display:none" id="q_473336052">-- Galaxies meeting multiple simple criteria.
-- Find all galaxies with blue surface brightness between 23 and 25
-- mag per square arcseconds, and -10 < supergalactic latitude (sgb) < 10, and
-- declination less than zero. Currently, we have to live with ra/dec until we
-- get galactic coordinates. To calculate surface brightness per sq. arcsec,
-- we use (g + rho), where g is the blue magnitude, and rho= 5*log(r). This
-- query now has three requirements, one involving simple math.
--
-- On DR2, returns 61090 rows in 330 sec.
SELECT objID
FROM Galaxy
WHERE ra between 178 and 180
and dec < 0
-- and (g+rho) between 23 and 25
and g between (23-rho) and (25-rho)
-- g is the blue magnitude, and rho= 5*log(Petro radius)</textarea><textarea style="display:none" id="q_1038272356">-- Using spatial unit vectors for coordinate cuts.
-- Find galaxies in a given area of the sky, using a coordinate cut
-- in the unit vector cx,cy,cz that corresponds to a specific RA range.
-- Another simple query that uses math in the WHERE clause.
--
-- Finds 100 galaxies in 230 sec on DR2, but this is a very slow way to do
-- coordinate cuts. Using RA/dec is *much* faster due to indexing.
--
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT TOP 100 colc_g, colc_r
FROM Galaxy
WHERE
(-0.466 * cx + 0.689 * cy>=0)
and (-0.385 * cx - 0.173 * cy <0)
</textarea><textarea style="display:none" id="q_1673976505">-- Find CVs using colors.
-- Search for Cataclysmic Variables and pre-CVs with White Dwarfs and
-- very late secondaries. Just uses some simple color cuts from Paula Szkody.
-- Another simple query that uses math in the WHERE clause
--
-- Finishes in 72 sec on DR2.
SELECT TOP 10000 run,
camCol,
rerun,
field,
objID,
u, g, r, i, z,
ra, dec -- Just get some basic quantities
FROM PhotoPrimary -- From all primary detections, regardless of class
WHERE u - g < 0.4
and g - r < 0.7
and r - i > 0.4
and i - z > 0.4 -- that meet the color criteria
</textarea><textarea style="display:none" id="q_1262886835">-- Getting a subsample of the data.
-- Uses the integer short object id (obj) and the '%' syntax (like awk)
-- to get every 1000th object. THIS IS NOT A TRULY RANDOM SUBSET!
--
-- Returns 11367 objects in DR2 (in about 10-15mins).
SELECT u, g, r, i, z
FROM Galaxy with (nolock)
WHERE (objID%1000) = 1
AND (r between 18 and 21)
</textarea><textarea style="display:none" id="q_1206688596">-- Low-z QSO candidates using color cuts.
-- from Gordon Richards.
-- Also a simple query with a long WHERE clause.
SELECT TOP 1000 g, run, rerun, camcol, field, objID
FROM
Galaxy
WHERE (
(g <= 22) and
(u-g >= -0.27) and (u-g < 0.71) and
(g-r >= -0.24) and (g-r < 0.35) and
(r-i >= -0.27) and (r-i < 0.57) and
(i-z >= -0.35) and (i-z < 0.70)
)</textarea><textarea style="display:none" id="q_1341462147">-- Get object velocities and errors.
-- This is also a simple query that uses a WHERE clause.
-- However, now we perform a more complex mathematical operation.
SELECT TOP 1000
run, -- get a bunch of quantities
camCol,
field,
objID,
rowC, colC, rowV, colV, rowVErr, colVErr,
flags,
psfMag_u, psfMag_g, psfMag_r, psfMag_i, psfMag_z,
psfMagErr_u, psfMagErr_g, psfMagErr_r, psfMagErr_i, psfMagErr_z
FROM PhotoPrimary
WHERE ((rowv * rowv) / (rowvErr * rowvErr) +
(colv * colv) / (colvErr * colvErr) > 4)
-- where the velocities are reliable
</textarea><textarea style="display:none" id="q_1497461636">-- Using the BETWEEN syntax.
-- Find galaxies with an isophotal surface brightness (SB) larger
-- than 24 in the red band, and with an ellipticity > 0.5, and with the major
-- axis of the ellipse having a declination between 30" and 60" arc seconds.
-- This is also a simple query that uses a WHERE clause with three conditions
-- that must be met. We introduce the syntax 'BETWEEN' to do a range search.
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT TOP 100 ObjID
FROM Galaxy
WHERE r < 24 - rho
-- surface brightness brighter than 24 mag. per sq. arcsec in the red
-- Note that isolating r (indexed) on one side helps this run faster
and isoA_r between 30 and 60
-- major axis between 30" and 60"
and (power(q_r,2) + power(u_r,2)) > 0.25
-- square of ellipticity is > 0.5 squared. The SQL term 'power' is used for exponentiation.</textarea><textarea style="display:none" id="q_166620452">-- Moving objects consistent with an asteroid.
-- Also a simple query, but we introduce the 'as' syntax, which allows us to
-- name derived quantities in the result file.
--
--This Sample Query will not work for SDSS3 contexts
SELECT TOP 10
objID,
sqrt( power(rowv,2) + power(colv, 2) ) as velocity
FROM PhotoObj
WHERE
(power(rowv,2) + power(colv, 2)) between 50 and 1000
</textarea><textarea style="display:none" id="q_605771979">-- Find quasars in imaging data.
-- as specified by Xiaohui Fan et.al.
-- A rather straightforward query, just with many conditions.
SELECT TOP 1000 run,
camCol,
rerun,
field,
objID,
u, g, r, i, z,
ra, dec
FROM Star -- or Galaxy
WHERE ( u - g > 2.0 or u > 22.3 )
and ( i < 19 )
and ( i > 0 )
and ( g - r > 1.0 )
and ( r - i <
(0.08 + 0.42 * (g - r - 0.96) )
or g - r > 2.26 )
and ( i - z < 0.25 )
</textarea><textarea style="display:none" id="q_384152764">-- Using object counting and logic in a query.
-- Find all objects similar to the colors of a quasar at 5.5<redshift<6.5.
SELECT count(*) as 'total',
sum( case when (Type=3) then 1 else 0 end) as 'Galaxies',
sum( case when (Type=6) then 1 else 0 end) as 'Stars',
sum( case when (Type not in (3,6)) then 1 else 0 end) as 'Other'
FROM PhotoPrimary -- for each object
WHERE (( u - g > 2.0) or (u > 22.3) ) -- apply the quasar color cut.
and ( i between 0 and 19 )
and ( g - r > 1.0 )
and ( (r - i < 0.08 + 0.42 * (g - r - 0.96)) or (g - r > 2.26 ) )
and ( i - z < 0.25 )
</textarea><textarea style="display:none" id="q_239583990">-- Find galaxies that are blended with a star.
-- Output the deblended galaxy magnitudes.
-- This query introduces the use of multiple tables or views. You can assign
-- nicknames to tables as in the FROM clause below. Since you are using
-- multiple tables, you ,ust specify which table each quantity in the SELECT
-- clause comes from. Finally, the last line in the query is the join between
-- the two tables, which is achieved by requiring that a quantity present in
-- both tables be equal.
-- NOTE: This query times out (takes too long) without the "TOP 1000".
SELECT top 1000 G.ObjID, G.u, G.g, G.r, G.i, G.z --get the ObjID and final mags
FROM Galaxy G, Star S -- use two Views, Galaxy and Star, as a convenient mechanism to compare objects
WHERE G.parentID > 0 -- galaxy has a "parent", which tells us this object was deblended
and G.parentID = S.parentID -- and the star has the same parent
</textarea><textarea style="display:none" id="q_513883755">-- Stars selected using Field criteria.
-- Give me the PSF colors of all stars brighter than g=20 that have PSP_STATUS = 2.
-- Another simple multi-table query.
SELECT TOP 1000
s.psfMag_g, -- or whatever you want from each object
s.run,
s.camCol,
s.rerun,
s.field
FROM Star s, Field f
WHERE s.fieldID = f.fieldID
and s.psfMag_g < 20
and f.pspStatus = 2</textarea><textarea style="display:none" id="q_123633451">-- Objects selected by cuts on three tables.
-- Find the parameters for all objects in a selected field with
-- desired PSF width and range of columns.
-- Now we are using three tables, but it is still a simple query.
-- NOTE: This query times out (takes too long) without the "TOP 1000".
SELECT TOP 1000
f.run,
f.rerun,
f.camCol,
f.field,
p.objID,
p.ra,
p.dec,
p.Rowc,
p.Colc,
p.u,
p.modelMagErr_u ,
p.g,
p.modelMagErr_g,
p.r,
p.modelMagErr_r,
p.petroMag_r - p.extinction_r,
p.petroMagErr_r,
p.i,
p.modelMagErr_i,
p.z,
f.psfWidth_r
FROM
photoObj p, field f
WHERE
f.fieldid = p.fieldid
and f.psfWidth_r > 1.2
and p.colc > 400.0
</textarea><textarea style="display:none" id="q_964285562">-- Find all objects within 30 arcseconds of one another
-- that have very similar colors: that is where the color ratios
-- u-g, g-r, r-I are less than 0.05m.
SELECT TOP 10 P.ObjID -- distinct cases
FROM PhotoPrimary P, -- P is the primary object
Neighbors N, -- N is the neighbor link
PhotoPrimary L -- L is the lens candidate of P
WHERE P.ObjID = N.ObjID -- N is a neighbor record
and L.ObjID = N.NeighborObjID -- L is a neighbor of P
and P.ObjID < L. ObjID -- avoid duplicates
and abs((P.u-P.g)-(L.u-L.g))<0.05 -- L and P have similar spectra.
and abs((P.g-P.r)-(L.g-L.r))<0.05
and abs((P.r-P.i)-(L.r-L.i))<0.05
and abs((P.i-P.z)-(L.i-L.z))<0.05
</textarea><textarea style="display:none" id="q_1428429823">-- Find specific types of quasars using spectroscopy.
-- The easiest way to find quasars is by finding objects whose spectra have
-- been classified as quasars. This sample query searches the SpecObj
-- table for the IDs and redshifts of objects with the class column equal to 'QSO'
SELECT TOP 100 specObjID, z
FROM SpecObj
WHERE class = 'QSO' AND zWarning = 0
</textarea><textarea style="display:none" id="q_1014719417">-- Checking for errors using flags.
-- Another useful query is to see if the errors on moving (or
-- apparently moving) objects are correct. For example, it used to be that
-- some known QSOs were being flagged as moving objects. One way to look for
-- such objects is to compare the velocity to the error in velocity and see if
-- the "OBJECT1_MOVED" or "OBJECT2_BAD_MOVING_FIT" is set.
-- This query introduces bitwise logic for flags, and uses the 'as' syntax to
-- make the query more readable. Note that if a flag is not set, the value
-- will be zero. If you want to ensure multiple flags are not set, you can
-- either check that each individually is zero, or their sum is zero.
-- (From Gordon Richards)
SELECT TOP 1000
run,
rerun,
camcol,
field,
objID,
ra, dec,
rowv, colv,
rowvErr, colvErr,
i,
(flags & dbo.fPhotoFlags('MOVED')) as MOVED,
(flags & dbo.fPhotoFlags('BAD_MOVING_FIT')) as BAD_MOVING_FIT
FROM Galaxy
WHERE
(flags & (dbo.fPhotoFlags('MOVED') + dbo.fPhotoFlags('BAD_MOVING_FIT'))) > 0
and (rowv * rowv + colv * colv) >=
(rowvErr * rowvErr + colvErr * colvErr)</textarea><textarea style="display:none" id="q_955083894">-- Elliptical galaxies based on model fits.
-- Find all galaxies with a deVaucouleours profile and the
-- photometric colors consistent with an elliptical galaxy. NOTE THAT THE
-- NAMES and VALUES OF THE LIKELIHOODS HAVE CHANGED SINCE THE EDR; they are
-- now log likelihoods, and named accordingly (lDev is now lnlDev, etc.) to
-- indicate these are log likelihoods. This query has many conditions, and
-- also has the use of bitwise logic necessary for dealing with flags.
SELECT TOP 100 ObjID
FROM Galaxy as G
WHERE
G.lnlDev_r > G.lnlExp_r + 0.1
-- the likelihood of the deVaucouleours profile fit is 10% greater than the likelihood of the exponential fit
and G.lnlExp_r > -999
-- and the likelihoods are actually meaningful
and (G.flags & (dbo.fPhotoFlags('BINNED1') + dbo.fPhotoFlags('BINNED2') + dbo.fPhotoFlags('BINNED4'))) > 0
--and it is detected from at least one of the binned images ???
and (G.flags & ( dbo.fPhotoFlags('BLENDED') + dbo.fPhotoFlags('NODEBLEND') + dbo.fPhotoFlags('CHILD'))) != dbo.fPhotoFlags('BLENDED')
--and, if it is blended, it is either a child or not deblended further ??
and (G.flags & (dbo.fPhotoFlags('EDGE') + dbo.fPhotoFlags('SATURATED'))) = 0
-- and it is not near a ccd edge or saturated, where measurements may be bad
and G.petroMag_i > 17.5
-- and it is fainter than 17.5 in i-band
and (G.petroMag_r > 15.5 or G.petror50_r > 2)
and (G.petroMag_r > 0 and G.g > 0 and G.r > 0 and G.i > 0)
and ( (G.petroMag_r - G.extinction_r) < 19.2
and (G.petroMag_r - G.extinction_r <
(13.1 + (7/3)*(G.g - G.r) + 4 *(G.r - G.i) - 4 * 0.18 ) )
and ( (G.r - G.i - (G.g - G.r)/4 - 0.18) < 0.2 )
and ( (G.r - G.i - (G.g - G.r)/4 - 0.18) > -0.2 ) )
or ( (G.petroMag_r - G.extinction_r < 19.5)
and ( (G.r - G.i - (G.g - G.r)/4 - 0.18) >
(0.45 - 4*(G.g - G.r) ) )
and ( (G.g - G.r) > (1.35 + 0.25 *(G.r - G.i) ) ) )
-- and many constraints on colors and mags are met to make it have
-- elliptical-type colors.
</textarea><textarea style="display:none" id="q_2067166502">-- Galaxies with bluer centers.
-- by Michael Strauss. For all galaxies
-- with r_Petro < 18, not saturated, not bright, and not edge, give me those
-- with centers appreciably bluer than their outer parts, i.e., define the
-- center color as: u_psf - g_psf and define the outer color as: u_model -
-- g_model; give me all objs which have (u_model - g_model) - (u_psf - g_psf)
-- < -0.4
-- Another flags-based query.
SELECT TOP 1000
colc_u, colc_g, objID
FROM Galaxy
WHERE
( Flags & (dbo.fPhotoFlags('SATURATED') +
dbo.fPhotoFlags('BRIGHT') +
dbo.fPhotoFlags('EDGE')) ) = 0
and petrorad_r < 18
and ((colc_u - colc_g) - (psfMag_u - psfMag_g)) < -0.4</textarea><textarea style="display:none" id="q_1081925782">-- Diameter-limited sample of galaxies
-- from James Annis.
SELECT TOP 1000
run,
camCol,
rerun,
field,
objID,
ra,
dec
FROM Galaxy
WHERE ( flags & (dbo.fPhotoFlags('BINNED1')
+ dbo.fPhotoFlags('BINNED2')
+ dbo.fPhotoFlags('BINNED4')) ) > 0
and ( flags & (dbo.fPhotoFlags('BLENDED')
+ dbo.fPhotoFlags('NODEBLEND')
+ dbo.fPhotoFlags('CHILD')) ) != dbo.fPhotoFlags('BLENDED')
and ( ( (flags & dbo.fPhotoFlags('NOPETRO') = 0)
and petrorad_i > 15)
or ( (flags & dbo.fPhotoFlags('NOPETRO') > 0)
and petrorad_i > 7.5)
or ( (flags & dbo.fPhotoFlags('TOO_LARGE') > 0)
and petrorad_i > 2.5)
or
( (flags & dbo.fPhotoFlags('SATURATED') = 0)
and petrorad_i > 17.5) )
</textarea><textarea style="display:none" id="q_1379940380">-- Extremely red galaxies.
-- from James Annis.
-- Similar to the diameter limited sample query.
SELECT TOP 1000
g.run,
g.camCol,
g.rerun,
g.field,
g.objID,
g.ra, g.dec
FROM Field f, Galaxy g
WHERE
g.fieldID = f.fieldID
and ( g.flags & (dbo.fPhotoFlags('BINNED1')
+ dbo.fPhotoFlags('BINNED2')
+ dbo.fPhotoFlags('BINNED4')) ) > 0
and ( g.flags & (dbo.fPhotoFlags('BLENDED')
+ dbo.fPhotoFlags('NODEBLEND')
+ dbo.fPhotoFlags('CHILD')) ) != dbo.fPhotoFlags('BLENDED')
and ( g.flags & (dbo.fPhotoFlags('COSMIC_RAY')
+ dbo.fPhotoFlags('INTERP')) ) = 0
and f.psfWidth_r < 1.5
and (g.i - g.z > 1.0 ) -- i and z in primary tables DO NOT include extinction</textarea><textarea style="display:none" id="q_5571651">-- A version of the LRG sample.
-- by James Annis.
-- Another query with many conditions and flag tests.
SELECT TOP 100
run,
camCol,
rerun,
field,
objID,
ra,
dec
FROM Galaxy
WHERE ( ( flags & (dbo.fPhotoFlags('BINNED1')
+ dbo.fPhotoFlags('BINNED2')
+ dbo.fPhotoFlags('BINNED4')) ) > 0
and ( flags & (dbo.fPhotoFlags('BLENDED')
+ dbo.fPhotoFlags('NODEBLEND')
+ dbo.fPhotoFlags('CHILD')) ) != dbo.fPhotoFlags('BLENDED')
and ( flags & (dbo.fPhotoFlags('EDGE')
+ dbo.fPhotoFlags('SATURATED')) ) = 0
and petroMag_i > 17.5
and (petroMag_r > 15.5 or petror50_r > 2)
and (petroMag_r > 0 and g > 0 and r > 0 and i > 0)
and ( (petroMag_r-extinction_r) < 19.2
and (petroMag_r - extinction_r <
(13.1 + (7/3) * (dered_g - dered_r) + 4 * (dered_r - dered_i) - 4 * 0.18) )
and ( (dered_r - dered_i - (dered_g - dered_r)/4 - 0.18) < 0.2)
and ( (dered_r - dered_i - (dered_g - dered_r)/4 - 0.18) > -0.2)
--dered_ quantities already include extinction
and ( (petroMag_r - extinction_r +
2.5 * LOG10(2 * 3.1415 * petror50_r * petror50_r)) < 24.2) )
or ( (petroMag_r - extinction_r < 19.5)
and ( (dered_r - dered_i - (dered_g - dered_r)/4 - 0.18) > (0.45 - 4 * (dered_g - dered_r)) )
and ( (dered_g - dered_r) > (1.35 + 0.25 * (dered_r - dered_i)) ) )
and ( (petroMag_r - extinction_r +
2.5 * LOG10(2 * 3.1415 * petror50_r * petror50_r) ) < 23.3 ) )</textarea><textarea style="display:none" id="q_284612279">-- Find galaxies with specific spectra.
-- Namely, they have an equivalent width in
-- H_alpha > 40 Angstroms. We want object ID's from the photometry (Galaxy)
-- but constraints from spectroscopy. The line widths and IDs are stored in
-- SpecLine. --This is a simple query, but now we are using three tables. The
-- spectroscopy tables of measured lines are arranged non-intuitively, and we
-- urge users to read about them on the DAS help pages. --IMPORTANT NOTE:
-- Each spectroscopic object now has a match to at least two photometric
-- objects, one in Target and one in Best. Therefore, when performing a join
-- between spectroscopic photometric objects, you must specify either
-- PhotoObj.ObjID=SpecObj.bestObjID or PhotoObj.ObjID = SpecObj.targetObjID.
-- Normally, the default photometric database is BEST, so you will want to use
-- SpecObj.bestObjID
--
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT G.ObjID -- we want the photometric ObjID
FROM Galaxy as G, -- G is the galaxy
SpecObj as S, -- S is the spectra of galaxy G
SpecLine as L, -- L is a line of S
SpecLineNames as LN -- the names of the lines
WHERE G.ObjID = S.bestObjID -- connect the galaxy to the spectrum
and S.SpecObjID = L.SpecObjID -- and the spectral line L is detected in the spectrum
and L.LineId = LN.value -- L is the H alpha line
and LN.name = 'Ha_6565'
and L.ew > 40 -- and H alpha is at least 40 angstroms wide.
</textarea><textarea style="display:none" id="q_1514959216">-- Find galaxies with more specific spectra.
-- Same as prior query, but also require weak Hbeta line (Halpha/Hbeta > 20.)
--
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT G.ObjID -- return qualifying galaxies
FROM Galaxy as G, -- G is the galaxy
SpecObj as S, -- S is the spectra of galaxy G
SpecLine as L1, -- L1 is a line of S
SpecLine as L2, -- L2 is a second line of S
specLineNames as LN1, -- the names of the lines (Halpha)
specLineNames as LN2 -- the names of the lines (Hbeta)
WHERE G.ObjID = S.BestObjID -- connect the galaxy to the spectrum
and S.SpecObjID = L1.SpecObjID -- L1 is a line of S.
and S.SpecObjID = L2.SpecObjID -- L2 is a line of S.
and L1.LineId = LN1. value
and LN1.name = 'Ha_6565' -- L1 is the H alpha line
and L2.LineId = LN2.value -- L2 is the H alpha line
and LN2.name = 'Hb_4863' --
and L1.ew > 200 -- BIG Halpha
and L2.ew > 10 -- significant Hbeta emission line
and L2.ew * 20 < L1.ew -- Hbeta is comparatively small
</textarea><textarea style="display:none" id="q_1269992360">-- Find binary stars with specific colors.
-- At least one of them should have the colors of a white dwarf.
SELECT TOP 100 s1.objID as s1, s2.objID as s2
FROM Star S1, -- S1 is the white dwarf
Neighbors N, -- N is the precomputed neighbors links
Star S2 -- S2 is the second star
WHERE S1.objID = N. objID -- S1 and S2 are neighbors-within 30 arc sec
and S2.objID = N.NeighborObjID
and N.neighborType = dbo.fPhotoType('Star') -- and S2 is a star
and N.distance < .05 -- the 3 arcsecond test
and ((S1.u - S1.g) < 0.4 ) -- and S1 meets Paul Szkodys color cut for
and (S1.g - S1.r) < 0.7 -- white dwarfs.
and (S1.r - S1.i) > 0.4
and (S1.i - S1.z) > 0.4
</textarea><textarea style="display:none" id="q_1619536327">-- Find quasars with a broad absorption line and a nearby galaxy.
-- within 10 arcseconds.
-- Return both the quasars and the galaxies.
--
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT Q.BestObjID as Quasar_candidate_ID , G.ObjID as Galaxy_ID, N.distance
FROM SpecObj as Q, -- Q is the specObj of the quasar candidate
Neighbors as N, -- N is the Neighbors list of Q
Galaxy as G, -- G is the nearby galaxy
SpecClass as SC, -- Spec Class
SpecLine as L, -- L is the broad line we are looking for
SpecLineNames as LN -- Line Name
WHERE Q.SpecClass =SC.value -- Q is a QSO
and SC.name in ('QSO', 'HIZ_QSO') -- Spectrum says "QSO"
and Q.SpecObjID = L.SpecObjID -- L is a spectral line of Q.
and L.LineID = LN.value -- line found and
and LN.Name != 'UNKNOWN' -- not not identified
and L.ew < -10 -- but its a prominent absorption line
and Q.BestObjID = N.ObjID -- N is a neighbor record
and G.ObjID = N.NeighborObjID -- G is a neighbor of Q
and N.distance < 10.0/60 -- and it is within 10 arcseconds of the Q.
</textarea><textarea style="display:none" id="q_234499396">-- Find galaxies without saturated pixels within 1' of a given point.
-- ra=185.0, dec=-0.5. This query uses a function fGetNearbyObjEq,
-- which takes 3 arguments (ra,dec, distance in arcmin); this function uses
-- the Neighbors table. The Neighbors table and the Galaxy table have in
-- common the objID, so we have to select objects from both where the objIDs
-- are the same. The output of the function is a table with the Galaxy Object
-- ID and distance in arcmin from the input. This query introduces the use of
-- a JOIN to combine table contents. Also, we use the 'orDER BY' syntax,
-- which will sort the output.
SELECT TOP 100 G.objID, GN.distance
FROM Galaxy as G
JOIN dbo.fGetNearbyObjEq(185.,-0.5, 1) as GN -- this function outputs a table, so we have to do a join
on G.objID = GN.objID -- get objects from temporary neighbors table GN with desired ObjID
WHERE (G.flags & dbo.fPhotoFlags('saturated')) = 0 -- and the object is not saturated. f.PhotoFlags is a function that interprets the flag bits.
ORDER BY distance -- sort these by distance
</textarea><textarea style="display:none" id="q_386537157">-- Ellipticals with odd lines.
-- Find all elliptical galaxies with spectra that have an anomalous
-- emission line. This query introduces the SQL syntax DISTINCT, which will
-- return only one instance of the requested parameter (ObjID, in this case),
-- because our query may return the same object more than once. This is also
-- the first nested query, where we use one SELECT (the inner one) to get a
-- group of objects we are not interested in. The outer SELECT includes the
-- new syntax 'not in', which is used to perform the exclusion.
--
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT DISTINCT G.ObjID -- return qualifying galaxies
FROM
Galaxy as G, -- G is the galaxy
SpecObjAll as S, -- S is the spectra of galaxy G
SpecLineAll as L, -- L is a line of S
-- we must use SpecLineAll because SpecLine only has ID's lines
XCRedshift as XC -- the template cross-correlation redshift
WHERE G.ObjID = S.bestObjID -- connect galaxy to the spectrum
and S.SpecObjID = L.SpecObjID -- The line L must be in the spectrum S
and S.SpecObjID = XC.SpecObjID -- and there is a crosscorrelation redshift
and XC.tempNo = 8 -- Template('Elliptical') -- best Cross correlation template used is "elliptical"
and L.LineID = 0
and L.ew > 10 -- and the line is prominent by some definition, in this case, the equivalent width is over 10 Angstroms
and S.SpecObjID not in (
-- insist that there are no other lines
SELECT S.SpecObjID -- This is the chosen line.
FROM SpecLine as L1 -- L1 is another line...
-- by using SpecLine, we are automatically requiring that the line
-- be identified
WHERE S.SpecObjID = L1.SpecObjID -- ...for this object...
and abs(L.wave - L1.wave) <.01
-- ...at nearly the same wavelength...
)
</textarea><textarea style="display:none" id="q_506396296">-- Search near BCG galaxies.
-- For each galaxy in the BCG data set (brightest cluster galaxy),
-- in 160<right ascension<170, -25<declination<35 count the number of
-- galaxies within 30" of it that have a photoz within 0.05
-- of that galaxy.
-- An extremely complex WHERE clause.
SELECT G.objID, count(N.NeighborObjID) as pop
FROM Galaxy as G, -- first gravitational lens candidate
Neighbors as N, -- precomputed list of neighbors
Galaxy as U, -- a neighbor galaxy of G
photoZ as Gpz, -- photoZ of G.
photoZ as Npz -- Neighbor photoZ
WHERE G.ra between 160 and 170
and G.dec between -5 and 5
and G.objID = N.objID -- connect G and U via the neighbors table
and U.objID = N.neighborObjID -- so that we know G and U are within
and N.objID < N.neighborObjID -- 30 arcseconds of one another.
and G.objID = Gpz.objID
and U.objID = Npz.objID
and abs(Gpz.Z - Npz.Z) < 0.05 -- restrict the photoZ differences
and (G.flags & (dbo.fPhotoFlags('BINNED1') + dbo.fPhotoFlags('BINNED2') + dbo.fPhotoFlags('BINNED4'))) > 0
--and it is detected from at least one of the binned images
and (G.flags & ( dbo.fPhotoFlags('BLENDED') + dbo.fPhotoFlags('NODEBLEND') + dbo.fPhotoFlags('CHILD'))) != dbo.fPhotoFlags('BLENDED')
--and, if it is blended, it is either a child or not deblended further ??
and (G.flags & (dbo.fPhotoFlags('EDGE') + dbo.fPhotoFlags('SATURATED'))) = 0
-- and it is not near a ccd edge or saturated, where measurements may be bad
-- and apply color cut for a BCG courtesy of James Annis of Fermilab
and G.petroMag_i > 17.5
and (G.petroMag_r > 15.5 or G.petror50_r > 2)
and (G.petroMag_r < 30 and G.g < 30 and G.r < 30 and G.i < 30)
and (G.r < 19.2
and ( 1=1 or -- huh?
(G.r < (13.1 + (7/3)*(G.g - G.r) +
-- deRed_r < 13.1 + 0.7 / 0.3 * deRed_gr
4 *(G.r - G.i - 0.18 ))
-- 1.2 / 0.3 * deRed_ri
and (( G.r - G.i - (G.g - G.r)/4 - 0.18) BETWEEN -0.2 and 0.2 )
and ((G.r +
-- petSB - deRed_r + 2.5 log10(2Pi*petror50^2)
2.5 * LOG( 2 * 3.1415 * G.petror50_r * G.petror50_r )) < 24.2 )
)
or
( (G.r < 19.5 )
and (( G.r - G.i -(G.g - G.r)/4 -.18) >
-- - deRed_gr/4 - 0.18
-- cperp = deRed_ri
(0.45 - 4*( G.g - G.r)))
-- 0.45 - deRed_gr/0.25
and ((G.g - G.r) > ( 1.35 + 0.25 *(G.r - G.i)))
and ((G.r +
-- petSB - deRed_r + 2.5 log10(2Pi*petror50^2)
2.5 * LOG( 2 * 3.1415 * G.petror50_r * G.petror50_r )) < 23.3 )
)) )
group by G.objID
</textarea><textarea style="display:none" id="q_1230693149">-- Broadest line of each spectrum with its ID.
-- (or more generally, all the columns for
-- the spectral line with the highest/lowest something)? The line width is
-- stored in the column sigma, the identification is in the column restwave.
-- (Sebastian Jester )
--
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT
L.specObjId,
L.specLineID,
sMax.Maxwidth -- get the spectroscopic object ID, the line ID, and the width
FROM specLine L,
(SELECT specObjID,
Max(waveMax-waveMin) as MaxWidth
-- Define MaxWidth as the largest difference in the min and max wavelength of
-- an identified line, using the built-in Max function of SQL
FROM SpecLine
GROUP BY specObjID) as sMax
-- sMax contains a single specObjID and MaxWidth. Remember that for each line
-- identified in a given object's spectrum, there is an entry in
-- SpecLine. This means that each specObjID appears many times in SpecLine,
-- once for each line found, and they must be aggregated before performing any
-- operation such as Max. The GROUP BY is thus NECESSARY.
-- The upper FROM clause is telling us we will use the table SpecLine and this
-- new output called sMax, which contains one entry with the SpecObjID and
-- MaxWidth. If we used some other function instead of 'Max', such as 'top
-- 10', sMax would have more than row.
WHERE
L.specObjID = sMax.specObjID
and (L.waveMax-L.waveMin) = sMax.MaxWidth
-- Just as with the specObjID, each specLineID appears many times in specLine.
-- This final WHERE clause makes sure we get the one specLineID from SpecObj
-- which matches the unique combination of specObjID and MaxWidth in sMax.
</textarea><textarea style="display:none" id="q_2026053022">-- Gridded galaxy counts and masks. Actually consists of TWO queries:
-- 1) Create a gridded count of galaxies with u-g > 1 and r < 21.5 over -1 < dec < 1,
-- and 179 < R.A. < 181, on a grid, and create a map of masks over the same grid.
-- Scan the table for galaxies and group them in cells 2 arc-minuteson a side. Provide
-- predicates for the color restrictions on u-g and r and to limit the search to the
-- portion of the sky defined by the right ascension and declination conditions. Return
-- the count of qualifying galaxies in each cell.
-- 2) Run another query with the same grouping, but with a predicate to include only
-- objects such as satellites, planets, and airplanes that obscure the cell. The second
-- query returns a list of cell coordinates that serve as a mask for the first query.
--- First find the gridded galaxy count (with the color cut)
--- In local tangent plane, ra/cos(dec) is a linear degree.
SELECT cast((ra/cos(cast(dec*30 as int)/30.0))*30 as int)/30.0 as raCosDec,
cast(dec*30 as int)/30.0 as dec,
count(*) as pop
FROM Galaxy as G
JOIN dbo.fHTMCoverRegion('CHULL J2000 179 -1 179 1 181 1 181 -1') AS T
ON G.htmID BETWEEN T.HTMIDstart AND T. HTMIDend
WHERE ra between 179 and 181
and dec between -1 and 1
and u-g > 1
and r < 21.5
GROUP BY cast((ra/cos(cast(dec*30 as int)/30.0))*30 as int)/30.0,
cast(dec*30 as int)/30.0
-- now build mask grid.
-- This is a separate query if no temp tables can be made
SELECT cast((ra/cos(cast(dec*30 as int)/30.0))*30 as int)/30.0 as raCosDec,
cast(dec*30 as int)/30.0 as dec,
count(*) as pop
FROM PhotoObj as PO
JOIN dbo.fHTMCoverRegion('CHULL J2000 179 -1 179 1 181 1 181 -1') AS T
ON PO.htmID BETWEEN T.HTMIDstart AND T.HTMIDend
JOIN PhotoType as PT ON PO.type = PT.value
WHERE
ra between 179 and 181
and dec between -1 and 1
and PT.name in ('COSMIC_RAY', 'DEFECT', 'GHOST', 'TRAIL', 'UNKNOWN')
GROUP BY cast((ra/cos(cast(dec*30 as int)/30.0))*30 as int)/30.0,
cast(dec*30 as int)/30.0 </textarea><textarea style="display:none" id="q_643163052">-- Create a count of galaxies for each of the HTM triangles.
-- Galaxies should satisfy a certain color cut,
-- like 0.7u-0.5g-0.2i<1.25 && r<21.75, output it in a form
-- adequate for visualization.
SELECT (htmID / power(2,24)) as htm_8 ,
-- group by 8-deep HTMID (rshift HTM by 12)
avg(ra) as ra,
avg(dec) as [dec],
count(*) as pop -- return center point and count for display
FROM Galaxy -- only look at galaxies
WHERE (0.7*u - 0.5*g - 0.2*i) < 1.25 -- meeting this color cut
and r < 21.75 -- brighter than 21.75 magnitude in red band.
group by (htmID /power(2,24)) -- group into 8-deep HTM buckets.
</textarea><textarea style="display:none" id="q_1483607040">-- Find stars with multiple measurements with magnitude variations >0.1.
-- Note that this runs very slowly unless explicit workarounds are included
-- for some SQLServer Optimizer bugs, which are NOT included here
SELECT TOP 100
S1.objID as objID1, S2.objID as ObjID2 -- select object IDs of star and its pair
FROM Star as S1, -- the primary star
photoObj as S2, -- the second observation of the star
neighbors as N -- the neighbor record
WHERE S1.objID = N.objID -- insist the stars are neighbors
and S2.objID = N.neighborObjID -- using precomputed neighbors table
and distance < 0.5/60 -- distance is 0.5 arc second or less
and S1.run != S2.run -- observations are two different runs
and S2.type = dbo.fPhotoType('Star') -- S2 is indeed a star
and S1.u between 1 and 27 -- S1 magnitudes are reasonable
and S1.g between 1 and 27
and S1.r between 1 and 27
and S1.i between 1 and 27
and S1.z between 1 and 27
and S2.u between 1 and 27 -- S2 magnitudes are reasonable.
and S2.g between 1 and 27
and S2.r between 1 and 27
and S2.i between 1 and 27
and S2.z between 1 and 27
and ( -- and one of the colors is different.
abs(S1.u-S2.u) > .1 + (abs(S1.Err_u) + abs(S2.Err_u))
or abs(S1.g-S2.g) > .1 + (abs(S1.Err_g) + abs(S2.Err_g))
or abs(S1.r-S2.r) > .1 + (abs(S1.Err_r) + abs(S2.Err_r))
or abs(S1.i-S2.i) > .1 + (abs(S1.Err_i) + abs(S2.Err_i))
or abs(S1.z-S2.z) > .1 + (abs(S1.Err_z) + abs(S2.Err_z))
)
</textarea><textarea style="display:none" id="q_1458312124">-- This query uses the new SQL Server 2005 CROSS APPLY and OUTER APPLY
-- constructs to apply a table-valued function to the results of a query.
-- In this example, we use the fFootPrintEq function which returns a list
-- of SDSS regions that intersect the area specified by the RA, dec and
-- radius, or NULL if the area is outside the SDSS footprint.
-- For each point in the input list, in this case the result of a query
-- on PhotoObj, return "yes" or "no" depending on whether the point is in
-- the SDSS footprint or not, and any other needed columns.
SELECT top 100 objID, ra, dec,
(case when p.type is null then 'NO' else 'YES' end) as found
FROM PhotoObj AS p
OUTER APPLY dbo.fFootprintEq(ra,dec,0.1)
WHERE (ra between 179.5 and 182.3) and (dec between -1.0 and 1.8)
</textarea>
<textarea style="display:none" id="q_998698239">-- Basic_SELECT_FROM_WHERE
-- Find objects in a particular field.
SELECT objID,
field, ra, dec -- Get the unique object ID, field number, and coords
FROM PhotoObj -- From the photometric data
WHERE fieldID = 587722951961673728 -- that is in a specific field
</textarea><textarea style="display:none" id="q_324753475">-- Galaxies meeting two simple criteria.
-- Find all galaxies brighter than r magnitude 17, where the local
-- extinction is > 0.275. This is a simple query that uses a WHERE clause,
-- but now two conditions that must be met simultaneously.
--
-- Finds 6604 galaxies in under 10 mins on DR2, but beware that increasing
-- the limiting r magnitude will significantly add to the execution time.
SELECT objID
FROM Galaxy
WHERE
r < 17 -- r IS NOT deredenned
and extinction_r > 0.275 -- extinction more than 0.175
</textarea><textarea style="display:none" id="q_638887334">-- Find all objects with unclassified spectra.
-- A simple SELECT-FROM-WHERE query, using a function
--
-- On DR2, returns 3109 rows in 20 sec.
SELECT specObjID
FROM SpecObj
WHERE SpecClass = dbo.fSpecClass('UNKNOWN')</textarea><textarea style="display:none" id="q_1942123503">-- Galaxies meeting multiple simple criteria.
-- Find all galaxies with blue surface brightness between 23 and 25
-- mag per square arcseconds, and -10 < supergalactic latitude (sgb) < 10, and
-- declination less than zero. Currently, we have to live with ra/dec until we
-- get galactic coordinates. To calculate surface brightness per sq. arcsec,
-- we use (g + rho), where g is the blue magnitude, and rho= 5*log(r). This
-- query now has three requirements, one involving simple math.
--
-- On DR2, returns 61090 rows in 330 sec.
SELECT objID
FROM Galaxy
WHERE ra between 178 and 180
and dec < 0
-- and (g+rho) between 23 and 25
and g between (23-rho) and (25-rho)
-- g is the blue magnitude, and rho= 5*log(Petro radius)</textarea><textarea style="display:none" id="q_1122950537">-- Using spatial unit vectors for coordinate cuts.
-- Find galaxies in a given area of the sky, using a coordinate cut
-- in the unit vector cx,cy,cz that corresponds to a specific RA range.
-- Another simple query that uses math in the WHERE clause.
--
-- Finds 100 galaxies in 230 sec on DR2, but this is a very slow way to do
-- coordinate cuts. Using RA/dec is *much* faster due to indexing.
--
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT TOP 100 colc_g, colc_r
FROM Galaxy
WHERE
(-0.466 * cx + 0.689 * cy>=0)
and (-0.385 * cx - 0.173 * cy <0)
</textarea><textarea style="display:none" id="q_203970260">-- Find CVs using colors.
-- Search for Cataclysmic Variables and pre-CVs with White Dwarfs and
-- very late secondaries. Just uses some simple color cuts from Paula Szkody.
-- Another simple query that uses math in the WHERE clause
--
-- Finishes in 72 sec on DR2.
SELECT TOP 10000 run,
camCol,
rerun,
field,
objID,
u, g, r, i, z,
ra, dec -- Just get some basic quantities
FROM PhotoPrimary -- From all primary detections, regardless of class
WHERE u - g < 0.4
and g - r < 0.7
and r - i > 0.4
and i - z > 0.4 -- that meet the color criteria
</textarea><textarea style="display:none" id="q_155362706">-- Getting a subsample of the data.
-- Uses the integer short object id (obj) and the '%' syntax (like awk)
-- to get every 1000th object. THIS IS NOT A TRULY RANDOM SUBSET!
--
-- Returns 11367 objects in DR2 (in about 10-15mins).
SELECT u, g, r, i, z
FROM Galaxy with (nolock)
WHERE (objID%1000) = 1
AND (r between 18 and 21)
</textarea><textarea style="display:none" id="q_2008048623">-- Low-z QSO candidates using color cuts.
-- from Gordon Richards.
-- Also a simple query with a long WHERE clause.
SELECT TOP 1000 g, run, rerun, camcol, field, objID
FROM
Galaxy
WHERE (
(g <= 22) and
(u-g >= -0.27) and (u-g < 0.71) and
(g-r >= -0.24) and (g-r < 0.35) and
(r-i >= -0.27) and (r-i < 0.57) and
(i-z >= -0.35) and (i-z < 0.70)
)</textarea><textarea style="display:none" id="q_468185944">-- Get object velocities and errors.
-- This is also a simple query that uses a WHERE clause.
-- However, now we perform a more complex mathematical operation.
SELECT TOP 1000
run, -- get a bunch of quantities
camCol,
field,
objID,
rowC, colC, rowV, colV, rowVErr, colVErr,
flags,
psfMag_u, psfMag_g, psfMag_r, psfMag_i, psfMag_z,
psfMagErr_u, psfMagErr_g, psfMagErr_r, psfMagErr_i, psfMagErr_z
FROM PhotoPrimary
WHERE ((rowv * rowv) / (rowvErr * rowvErr) +
(colv * colv) / (colvErr * colvErr) > 4)
-- where the velocities are reliable
</textarea><textarea style="display:none" id="q_1741581729">-- Using the BETWEEN syntax.
-- Find galaxies with an isophotal surface brightness (SB) larger
-- than 24 in the red band, and with an ellipticity > 0.5, and with the major
-- axis of the ellipse having a declination between 30" and 60" arc seconds.
-- This is also a simple query that uses a WHERE clause with three conditions
-- that must be met. We introduce the syntax 'BETWEEN' to do a range search.
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT TOP 100 ObjID
FROM Galaxy
WHERE r < 24 - rho
-- surface brightness brighter than 24 mag. per sq. arcsec in the red
-- Note that isolating r (indexed) on one side helps this run faster
and isoA_r between 30 and 60
-- major axis between 30" and 60"
and (power(q_r,2) + power(u_r,2)) > 0.25
-- square of ellipticity is > 0.5 squared. The SQL term 'power' is used for exponentiation.</textarea><textarea style="display:none" id="q_293030657">-- Moving objects consistent with an asteroid.
-- Also a simple query, but we introduce the 'as' syntax, which allows us to
-- name derived quantities in the result file.
--
--This Sample Query will not work for SDSS3 contexts
SELECT TOP 10
objID,
sqrt( power(rowv,2) + power(colv, 2) ) as velocity
FROM PhotoObj
WHERE
(power(rowv,2) + power(colv, 2)) between 50 and 1000
</textarea><textarea style="display:none" id="q_50066576">-- Find quasars in imaging data.
-- as specified by Xiaohui Fan et.al.
-- A rather straightforward query, just with many conditions.
SELECT TOP 1000 run,
camCol,
rerun,
field,
objID,
u, g, r, i, z,
ra, dec
FROM Star -- or Galaxy
WHERE ( u - g > 2.0 or u > 22.3 )
and ( i < 19 )
and ( i > 0 )
and ( g - r > 1.0 )
and ( r - i <
(0.08 + 0.42 * (g - r - 0.96) )
or g - r > 2.26 )
and ( i - z < 0.25 )
</textarea><textarea style="display:none" id="q_1227312257">-- Using object counting and logic in a query.
-- Find all objects similar to the colors of a quasar at 5.5<redshift<6.5.
SELECT count(*) as 'total',
sum( case when (Type=3) then 1 else 0 end) as 'Galaxies',
sum( case when (Type=6) then 1 else 0 end) as 'Stars',
sum( case when (Type not in (3,6)) then 1 else 0 end) as 'Other'
FROM PhotoPrimary -- for each object
WHERE (( u - g > 2.0) or (u > 22.3) ) -- apply the quasar color cut.
and ( i between 0 and 19 )
and ( g - r > 1.0 )
and ( (r - i < 0.08 + 0.42 * (g - r - 0.96)) or (g - r > 2.26 ) )
and ( i - z < 0.25 )
</textarea><textarea style="display:none" id="q_1009123441">-- Find galaxies that are blended with a star.
-- Output the deblended galaxy magnitudes.
-- This query introduces the use of multiple tables or views. You can assign
-- nicknames to tables as in the FROM clause below. Since you are using
-- multiple tables, you ,ust specify which table each quantity in the SELECT
-- clause comes from. Finally, the last line in the query is the join between
-- the two tables, which is achieved by requiring that a quantity present in
-- both tables be equal.
-- NOTE: This query times out (takes too long) without the "TOP 1000".
SELECT top 1000 G.ObjID, G.u, G.g, G.r, G.i, G.z --get the ObjID and final mags
FROM Galaxy G, Star S -- use two Views, Galaxy and Star, as a convenient mechanism to compare objects
WHERE G.parentID > 0 -- galaxy has a "parent", which tells us this object was deblended
and G.parentID = S.parentID -- and the star has the same parent
</textarea><textarea style="display:none" id="q_97947386">-- Stars selected using Field criteria.
-- Give me the PSF colors of all stars brighter than g=20 that have PSP_STATUS = 2.
-- Another simple multi-table query.
SELECT TOP 1000
s.psfMag_g, -- or whatever you want from each object
s.run,
s.camCol,
s.rerun,
s.field
FROM Star s, Field f
WHERE s.fieldID = f.fieldID
and s.psfMag_g < 20
and f.pspStatus = 2</textarea><textarea style="display:none" id="q_1715812784">-- Objects selected by cuts on three tables.
-- Find the parameters for all objects in a selected field with
-- desired PSF width and range of columns.
-- Now we are using three tables, but it is still a simple query.
-- NOTE: This query times out (takes too long) without the "TOP 1000".
SELECT TOP 1000
f.run,
f.rerun,
f.camCol,
f.field,
p.objID,
p.ra,
p.dec,
p.Rowc,
p.Colc,
p.u,
p.modelMagErr_u ,
p.g,
p.modelMagErr_g,
p.r,
p.modelMagErr_r,
p.petroMag_r - p.extinction_r,
p.petroMagErr_r,
p.i,
p.modelMagErr_i,
p.z,
f.psfWidth_r
FROM
photoObj p, field f
WHERE
f.fieldid = p.fieldid
and f.psfWidth_r > 1.2
and p.colc > 400.0
</textarea><textarea style="display:none" id="q_1301593803">-- Find all objects within 30 arcseconds of one another
-- that have very similar colors: that is where the color ratios
-- u-g, g-r, r-I are less than 0.05m.
SELECT TOP 10 P.ObjID -- distinct cases
FROM PhotoPrimary P, -- P is the primary object
Neighbors N, -- N is the neighbor link
PhotoPrimary L -- L is the lens candidate of P
WHERE P.ObjID = N.ObjID -- N is a neighbor record
and L.ObjID = N.NeighborObjID -- L is a neighbor of P
and P.ObjID < L. ObjID -- avoid duplicates
and abs((P.u-P.g)-(L.u-L.g))<0.05 -- L and P have similar spectra.
and abs((P.g-P.r)-(L.g-L.r))<0.05
and abs((P.r-P.i)-(L.r-L.i))<0.05
and abs((P.i-P.z)-(L.i-L.z))<0.05
</textarea><textarea style="display:none" id="q_1729284068">-- Find specific types of quasars using spectroscopy.
-- The easiest way to find quasars is by finding objects whose spectra have
-- been classified as quasars. This sample query searches the SpecObj
-- table for the IDs and redshifts of objects with the class column equal to 'QSO'
SELECT TOP 100 specObjID, z
FROM SpecObj
WHERE class = 'QSO' AND zWarning = 0
</textarea><textarea style="display:none" id="q_1709778956">-- Checking for errors using flags.
-- Another useful query is to see if the errors on moving (or
-- apparently moving) objects are correct. For example, it used to be that
-- some known QSOs were being flagged as moving objects. One way to look for
-- such objects is to compare the velocity to the error in velocity and see if
-- the "OBJECT1_MOVED" or "OBJECT2_BAD_MOVING_FIT" is set.
-- This query introduces bitwise logic for flags, and uses the 'as' syntax to
-- make the query more readable. Note that if a flag is not set, the value
-- will be zero. If you want to ensure multiple flags are not set, you can
-- either check that each individually is zero, or their sum is zero.
-- (From Gordon Richards)
SELECT TOP 1000
run,
rerun,
camcol,
field,
objID,
ra, dec,
rowv, colv,
rowvErr, colvErr,
i,
(flags & dbo.fPhotoFlags('MOVED')) as MOVED,
(flags & dbo.fPhotoFlags('BAD_MOVING_FIT')) as BAD_MOVING_FIT
FROM Galaxy
WHERE
(flags & (dbo.fPhotoFlags('MOVED') + dbo.fPhotoFlags('BAD_MOVING_FIT'))) > 0
and (rowv * rowv + colv * colv) >=
(rowvErr * rowvErr + colvErr * colvErr)</textarea><textarea style="display:none" id="q_1346173317">-- Elliptical galaxies based on model fits.
-- Find all galaxies with a deVaucouleours profile and the
-- photometric colors consistent with an elliptical galaxy. NOTE THAT THE
-- NAMES and VALUES OF THE LIKELIHOODS HAVE CHANGED SINCE THE EDR; they are
-- now log likelihoods, and named accordingly (lDev is now lnlDev, etc.) to
-- indicate these are log likelihoods. This query has many conditions, and
-- also has the use of bitwise logic necessary for dealing with flags.
SELECT TOP 100 ObjID
FROM Galaxy as G
WHERE
G.lnlDev_r > G.lnlExp_r + 0.1
-- the likelihood of the deVaucouleours profile fit is 10% greater than the likelihood of the exponential fit
and G.lnlExp_r > -999
-- and the likelihoods are actually meaningful
and (G.flags & (dbo.fPhotoFlags('BINNED1') + dbo.fPhotoFlags('BINNED2') + dbo.fPhotoFlags('BINNED4'))) > 0
--and it is detected from at least one of the binned images ???
and (G.flags & ( dbo.fPhotoFlags('BLENDED') + dbo.fPhotoFlags('NODEBLEND') + dbo.fPhotoFlags('CHILD'))) != dbo.fPhotoFlags('BLENDED')
--and, if it is blended, it is either a child or not deblended further ??
and (G.flags & (dbo.fPhotoFlags('EDGE') + dbo.fPhotoFlags('SATURATED'))) = 0
-- and it is not near a ccd edge or saturated, where measurements may be bad
and G.petroMag_i > 17.5
-- and it is fainter than 17.5 in i-band
and (G.petroMag_r > 15.5 or G.petror50_r > 2)
and (G.petroMag_r > 0 and G.g > 0 and G.r > 0 and G.i > 0)
and ( (G.petroMag_r - G.extinction_r) < 19.2
and (G.petroMag_r - G.extinction_r <
(13.1 + (7/3)*(G.g - G.r) + 4 *(G.r - G.i) - 4 * 0.18 ) )
and ( (G.r - G.i - (G.g - G.r)/4 - 0.18) < 0.2 )
and ( (G.r - G.i - (G.g - G.r)/4 - 0.18) > -0.2 ) )
or ( (G.petroMag_r - G.extinction_r < 19.5)
and ( (G.r - G.i - (G.g - G.r)/4 - 0.18) >
(0.45 - 4*(G.g - G.r) ) )
and ( (G.g - G.r) > (1.35 + 0.25 *(G.r - G.i) ) ) )
-- and many constraints on colors and mags are met to make it have
-- elliptical-type colors.
</textarea><textarea style="display:none" id="q_874416063">-- Galaxies with bluer centers.
-- by Michael Strauss. For all galaxies
-- with r_Petro < 18, not saturated, not bright, and not edge, give me those
-- with centers appreciably bluer than their outer parts, i.e., define the
-- center color as: u_psf - g_psf and define the outer color as: u_model -
-- g_model; give me all objs which have (u_model - g_model) - (u_psf - g_psf)
-- < -0.4
-- Another flags-based query.
SELECT TOP 1000
colc_u, colc_g, objID
FROM Galaxy
WHERE
( Flags & (dbo.fPhotoFlags('SATURATED') +
dbo.fPhotoFlags('BRIGHT') +
dbo.fPhotoFlags('EDGE')) ) = 0
and petrorad_r < 18
and ((colc_u - colc_g) - (psfMag_u - psfMag_g)) < -0.4</textarea><textarea style="display:none" id="q_1426553339">-- Diameter-limited sample of galaxies
-- from James Annis.
SELECT TOP 1000
run,
camCol,
rerun,
field,
objID,
ra,
dec
FROM Galaxy
WHERE ( flags & (dbo.fPhotoFlags('BINNED1')
+ dbo.fPhotoFlags('BINNED2')
+ dbo.fPhotoFlags('BINNED4')) ) > 0
and ( flags & (dbo.fPhotoFlags('BLENDED')
+ dbo.fPhotoFlags('NODEBLEND')
+ dbo.fPhotoFlags('CHILD')) ) != dbo.fPhotoFlags('BLENDED')
and ( ( (flags & dbo.fPhotoFlags('NOPETRO') = 0)
and petrorad_i > 15)
or ( (flags & dbo.fPhotoFlags('NOPETRO') > 0)
and petrorad_i > 7.5)
or ( (flags & dbo.fPhotoFlags('TOO_LARGE') > 0)
and petrorad_i > 2.5)
or
( (flags & dbo.fPhotoFlags('SATURATED') = 0)
and petrorad_i > 17.5) )
</textarea><textarea style="display:none" id="q_2092933015">-- Extremely red galaxies.
-- from James Annis.
-- Similar to the diameter limited sample query.
SELECT TOP 1000
g.run,
g.camCol,
g.rerun,
g.field,
g.objID,
g.ra, g.dec
FROM Field f, Galaxy g
WHERE
g.fieldID = f.fieldID
and ( g.flags & (dbo.fPhotoFlags('BINNED1')
+ dbo.fPhotoFlags('BINNED2')
+ dbo.fPhotoFlags('BINNED4')) ) > 0
and ( g.flags & (dbo.fPhotoFlags('BLENDED')
+ dbo.fPhotoFlags('NODEBLEND')
+ dbo.fPhotoFlags('CHILD')) ) != dbo.fPhotoFlags('BLENDED')
and ( g.flags & (dbo.fPhotoFlags('COSMIC_RAY')
+ dbo.fPhotoFlags('INTERP')) ) = 0
and f.psfWidth_r < 1.5
and (g.i - g.z > 1.0 ) -- i and z in primary tables DO NOT include extinction</textarea><textarea style="display:none" id="q_2046005064">-- A version of the LRG sample.
-- by James Annis.
-- Another query with many conditions and flag tests.
SELECT TOP 100
run,
camCol,
rerun,
field,
objID,
ra,
dec
FROM Galaxy
WHERE ( ( flags & (dbo.fPhotoFlags('BINNED1')
+ dbo.fPhotoFlags('BINNED2')
+ dbo.fPhotoFlags('BINNED4')) ) > 0
and ( flags & (dbo.fPhotoFlags('BLENDED')
+ dbo.fPhotoFlags('NODEBLEND')
+ dbo.fPhotoFlags('CHILD')) ) != dbo.fPhotoFlags('BLENDED')
and ( flags & (dbo.fPhotoFlags('EDGE')
+ dbo.fPhotoFlags('SATURATED')) ) = 0
and petroMag_i > 17.5
and (petroMag_r > 15.5 or petror50_r > 2)
and (petroMag_r > 0 and g > 0 and r > 0 and i > 0)
and ( (petroMag_r-extinction_r) < 19.2
and (petroMag_r - extinction_r <
(13.1 + (7/3) * (dered_g - dered_r) + 4 * (dered_r - dered_i) - 4 * 0.18) )
and ( (dered_r - dered_i - (dered_g - dered_r)/4 - 0.18) < 0.2)
and ( (dered_r - dered_i - (dered_g - dered_r)/4 - 0.18) > -0.2)
--dered_ quantities already include extinction
and ( (petroMag_r - extinction_r +
2.5 * LOG10(2 * 3.1415 * petror50_r * petror50_r)) < 24.2) )
or ( (petroMag_r - extinction_r < 19.5)
and ( (dered_r - dered_i - (dered_g - dered_r)/4 - 0.18) > (0.45 - 4 * (dered_g - dered_r)) )
and ( (dered_g - dered_r) > (1.35 + 0.25 * (dered_r - dered_i)) ) )
and ( (petroMag_r - extinction_r +
2.5 * LOG10(2 * 3.1415 * petror50_r * petror50_r) ) < 23.3 ) )</textarea><textarea style="display:none" id="q_1937139908">-- Find galaxies with specific spectra.
-- Namely, they have an equivalent width in
-- H_alpha > 40 Angstroms. We want object ID's from the photometry (Galaxy)
-- but constraints from spectroscopy. The line widths and IDs are stored in
-- SpecLine. --This is a simple query, but now we are using three tables. The
-- spectroscopy tables of measured lines are arranged non-intuitively, and we
-- urge users to read about them on the DAS help pages. --IMPORTANT NOTE:
-- Each spectroscopic object now has a match to at least two photometric
-- objects, one in Target and one in Best. Therefore, when performing a join
-- between spectroscopic photometric objects, you must specify either
-- PhotoObj.ObjID=SpecObj.bestObjID or PhotoObj.ObjID = SpecObj.targetObjID.
-- Normally, the default photometric database is BEST, so you will want to use
-- SpecObj.bestObjID
--
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT G.ObjID -- we want the photometric ObjID
FROM Galaxy as G, -- G is the galaxy
SpecObj as S, -- S is the spectra of galaxy G
SpecLine as L, -- L is a line of S
SpecLineNames as LN -- the names of the lines
WHERE G.ObjID = S.bestObjID -- connect the galaxy to the spectrum
and S.SpecObjID = L.SpecObjID -- and the spectral line L is detected in the spectrum
and L.LineId = LN.value -- L is the H alpha line
and LN.name = 'Ha_6565'
and L.ew > 40 -- and H alpha is at least 40 angstroms wide.
</textarea><textarea style="display:none" id="q_1071911477">-- Find galaxies with more specific spectra.
-- Same as prior query, but also require weak Hbeta line (Halpha/Hbeta > 20.)
--
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT G.ObjID -- return qualifying galaxies
FROM Galaxy as G, -- G is the galaxy
SpecObj as S, -- S is the spectra of galaxy G
SpecLine as L1, -- L1 is a line of S
SpecLine as L2, -- L2 is a second line of S
specLineNames as LN1, -- the names of the lines (Halpha)
specLineNames as LN2 -- the names of the lines (Hbeta)
WHERE G.ObjID = S.BestObjID -- connect the galaxy to the spectrum
and S.SpecObjID = L1.SpecObjID -- L1 is a line of S.
and S.SpecObjID = L2.SpecObjID -- L2 is a line of S.
and L1.LineId = LN1. value
and LN1.name = 'Ha_6565' -- L1 is the H alpha line
and L2.LineId = LN2.value -- L2 is the H alpha line
and LN2.name = 'Hb_4863' --
and L1.ew > 200 -- BIG Halpha
and L2.ew > 10 -- significant Hbeta emission line
and L2.ew * 20 < L1.ew -- Hbeta is comparatively small
</textarea><textarea style="display:none" id="q_1639576493">-- Find binary stars with specific colors.
-- At least one of them should have the colors of a white dwarf.
SELECT TOP 100 s1.objID as s1, s2.objID as s2
FROM Star S1, -- S1 is the white dwarf
Neighbors N, -- N is the precomputed neighbors links
Star S2 -- S2 is the second star
WHERE S1.objID = N. objID -- S1 and S2 are neighbors-within 30 arc sec
and S2.objID = N.NeighborObjID
and N.neighborType = dbo.fPhotoType('Star') -- and S2 is a star
and N.distance < .05 -- the 3 arcsecond test
and ((S1.u - S1.g) < 0.4 ) -- and S1 meets Paul Szkodys color cut for
and (S1.g - S1.r) < 0.7 -- white dwarfs.
and (S1.r - S1.i) > 0.4
and (S1.i - S1.z) > 0.4
</textarea><textarea style="display:none" id="q_2052665602">-- Find quasars with a broad absorption line and a nearby galaxy.
-- within 10 arcseconds.
-- Return both the quasars and the galaxies.
--
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT Q.BestObjID as Quasar_candidate_ID , G.ObjID as Galaxy_ID, N.distance
FROM SpecObj as Q, -- Q is the specObj of the quasar candidate
Neighbors as N, -- N is the Neighbors list of Q
Galaxy as G, -- G is the nearby galaxy
SpecClass as SC, -- Spec Class
SpecLine as L, -- L is the broad line we are looking for
SpecLineNames as LN -- Line Name
WHERE Q.SpecClass =SC.value -- Q is a QSO
and SC.name in ('QSO', 'HIZ_QSO') -- Spectrum says "QSO"
and Q.SpecObjID = L.SpecObjID -- L is a spectral line of Q.
and L.LineID = LN.value -- line found and
and LN.Name != 'UNKNOWN' -- not not identified
and L.ew < -10 -- but its a prominent absorption line
and Q.BestObjID = N.ObjID -- N is a neighbor record
and G.ObjID = N.NeighborObjID -- G is a neighbor of Q
and N.distance < 10.0/60 -- and it is within 10 arcseconds of the Q.
</textarea><textarea style="display:none" id="q_1227456513">-- Find galaxies without saturated pixels within 1' of a given point.
-- ra=185.0, dec=-0.5. This query uses a function fGetNearbyObjEq,
-- which takes 3 arguments (ra,dec, distance in arcmin); this function uses
-- the Neighbors table. The Neighbors table and the Galaxy table have in
-- common the objID, so we have to select objects from both where the objIDs
-- are the same. The output of the function is a table with the Galaxy Object
-- ID and distance in arcmin from the input. This query introduces the use of
-- a JOIN to combine table contents. Also, we use the 'orDER BY' syntax,
-- which will sort the output.
SELECT TOP 100 G.objID, GN.distance
FROM Galaxy as G
JOIN dbo.fGetNearbyObjEq(185.,-0.5, 1) as GN -- this function outputs a table, so we have to do a join
on G.objID = GN.objID -- get objects from temporary neighbors table GN with desired ObjID
WHERE (G.flags & dbo.fPhotoFlags('saturated')) = 0 -- and the object is not saturated. f.PhotoFlags is a function that interprets the flag bits.
ORDER BY distance -- sort these by distance
</textarea><textarea style="display:none" id="q_1795100394">-- Ellipticals with odd lines.
-- Find all elliptical galaxies with spectra that have an anomalous
-- emission line. This query introduces the SQL syntax DISTINCT, which will
-- return only one instance of the requested parameter (ObjID, in this case),
-- because our query may return the same object more than once. This is also
-- the first nested query, where we use one SELECT (the inner one) to get a
-- group of objects we are not interested in. The outer SELECT includes the
-- new syntax 'not in', which is used to perform the exclusion.
--
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT DISTINCT G.ObjID -- return qualifying galaxies
FROM
Galaxy as G, -- G is the galaxy
SpecObjAll as S, -- S is the spectra of galaxy G
SpecLineAll as L, -- L is a line of S
-- we must use SpecLineAll because SpecLine only has ID's lines
XCRedshift as XC -- the template cross-correlation redshift
WHERE G.ObjID = S.bestObjID -- connect galaxy to the spectrum
and S.SpecObjID = L.SpecObjID -- The line L must be in the spectrum S
and S.SpecObjID = XC.SpecObjID -- and there is a crosscorrelation redshift
and XC.tempNo = 8 -- Template('Elliptical') -- best Cross correlation template used is "elliptical"
and L.LineID = 0
and L.ew > 10 -- and the line is prominent by some definition, in this case, the equivalent width is over 10 Angstroms
and S.SpecObjID not in (
-- insist that there are no other lines
SELECT S.SpecObjID -- This is the chosen line.
FROM SpecLine as L1 -- L1 is another line...
-- by using SpecLine, we are automatically requiring that the line
-- be identified
WHERE S.SpecObjID = L1.SpecObjID -- ...for this object...
and abs(L.wave - L1.wave) <.01
-- ...at nearly the same wavelength...
)
</textarea><textarea style="display:none" id="q_1993463533">-- Search near BCG galaxies.
-- For each galaxy in the BCG data set (brightest cluster galaxy),
-- in 160<right ascension<170, -25<declination<35 count the number of
-- galaxies within 30" of it that have a photoz within 0.05
-- of that galaxy.
-- An extremely complex WHERE clause.
SELECT G.objID, count(N.NeighborObjID) as pop
FROM Galaxy as G, -- first gravitational lens candidate
Neighbors as N, -- precomputed list of neighbors
Galaxy as U, -- a neighbor galaxy of G
photoZ as Gpz, -- photoZ of G.
photoZ as Npz -- Neighbor photoZ
WHERE G.ra between 160 and 170
and G.dec between -5 and 5
and G.objID = N.objID -- connect G and U via the neighbors table
and U.objID = N.neighborObjID -- so that we know G and U are within
and N.objID < N.neighborObjID -- 30 arcseconds of one another.
and G.objID = Gpz.objID
and U.objID = Npz.objID
and abs(Gpz.Z - Npz.Z) < 0.05 -- restrict the photoZ differences
and (G.flags & (dbo.fPhotoFlags('BINNED1') + dbo.fPhotoFlags('BINNED2') + dbo.fPhotoFlags('BINNED4'))) > 0
--and it is detected from at least one of the binned images
and (G.flags & ( dbo.fPhotoFlags('BLENDED') + dbo.fPhotoFlags('NODEBLEND') + dbo.fPhotoFlags('CHILD'))) != dbo.fPhotoFlags('BLENDED')
--and, if it is blended, it is either a child or not deblended further ??
and (G.flags & (dbo.fPhotoFlags('EDGE') + dbo.fPhotoFlags('SATURATED'))) = 0
-- and it is not near a ccd edge or saturated, where measurements may be bad
-- and apply color cut for a BCG courtesy of James Annis of Fermilab
and G.petroMag_i > 17.5
and (G.petroMag_r > 15.5 or G.petror50_r > 2)
and (G.petroMag_r < 30 and G.g < 30 and G.r < 30 and G.i < 30)
and (G.r < 19.2
and ( 1=1 or -- huh?
(G.r < (13.1 + (7/3)*(G.g - G.r) +
-- deRed_r < 13.1 + 0.7 / 0.3 * deRed_gr
4 *(G.r - G.i - 0.18 ))
-- 1.2 / 0.3 * deRed_ri
and (( G.r - G.i - (G.g - G.r)/4 - 0.18) BETWEEN -0.2 and 0.2 )
and ((G.r +
-- petSB - deRed_r + 2.5 log10(2Pi*petror50^2)
2.5 * LOG( 2 * 3.1415 * G.petror50_r * G.petror50_r )) < 24.2 )
)
or
( (G.r < 19.5 )
and (( G.r - G.i -(G.g - G.r)/4 -.18) >
-- - deRed_gr/4 - 0.18
-- cperp = deRed_ri
(0.45 - 4*( G.g - G.r)))
-- 0.45 - deRed_gr/0.25
and ((G.g - G.r) > ( 1.35 + 0.25 *(G.r - G.i)))
and ((G.r +
-- petSB - deRed_r + 2.5 log10(2Pi*petror50^2)
2.5 * LOG( 2 * 3.1415 * G.petror50_r * G.petror50_r )) < 23.3 )
)) )
group by G.objID
</textarea><textarea style="display:none" id="q_477859480">-- Broadest line of each spectrum with its ID.
-- (or more generally, all the columns for
-- the spectral line with the highest/lowest something)? The line width is
-- stored in the column sigma, the identification is in the column restwave.
-- (Sebastian Jester )
--
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT
L.specObjId,
L.specLineID,
sMax.Maxwidth -- get the spectroscopic object ID, the line ID, and the width
FROM specLine L,
(SELECT specObjID,
Max(waveMax-waveMin) as MaxWidth
-- Define MaxWidth as the largest difference in the min and max wavelength of
-- an identified line, using the built-in Max function of SQL
FROM SpecLine
GROUP BY specObjID) as sMax
-- sMax contains a single specObjID and MaxWidth. Remember that for each line
-- identified in a given object's spectrum, there is an entry in
-- SpecLine. This means that each specObjID appears many times in SpecLine,
-- once for each line found, and they must be aggregated before performing any
-- operation such as Max. The GROUP BY is thus NECESSARY.
-- The upper FROM clause is telling us we will use the table SpecLine and this
-- new output called sMax, which contains one entry with the SpecObjID and
-- MaxWidth. If we used some other function instead of 'Max', such as 'top
-- 10', sMax would have more than row.
WHERE
L.specObjID = sMax.specObjID
and (L.waveMax-L.waveMin) = sMax.MaxWidth
-- Just as with the specObjID, each specLineID appears many times in specLine.
-- This final WHERE clause makes sure we get the one specLineID from SpecObj
-- which matches the unique combination of specObjID and MaxWidth in sMax.
</textarea><textarea style="display:none" id="q_1558845305">-- Gridded galaxy counts and masks. Actually consists of TWO queries:
-- 1) Create a gridded count of galaxies with u-g > 1 and r < 21.5 over -1 < dec < 1,
-- and 179 < R.A. < 181, on a grid, and create a map of masks over the same grid.
-- Scan the table for galaxies and group them in cells 2 arc-minuteson a side. Provide
-- predicates for the color restrictions on u-g and r and to limit the search to the
-- portion of the sky defined by the right ascension and declination conditions. Return
-- the count of qualifying galaxies in each cell.
-- 2) Run another query with the same grouping, but with a predicate to include only
-- objects such as satellites, planets, and airplanes that obscure the cell. The second
-- query returns a list of cell coordinates that serve as a mask for the first query.
--- First find the gridded galaxy count (with the color cut)
--- In local tangent plane, ra/cos(dec) is a linear degree.
SELECT cast((ra/cos(cast(dec*30 as int)/30.0))*30 as int)/30.0 as raCosDec,
cast(dec*30 as int)/30.0 as dec,
count(*) as pop
FROM Galaxy as G
JOIN dbo.fHTMCoverRegion('CHULL J2000 179 -1 179 1 181 1 181 -1') AS T
ON G.htmID BETWEEN T.HTMIDstart AND T. HTMIDend
WHERE ra between 179 and 181
and dec between -1 and 1
and u-g > 1
and r < 21.5
GROUP BY cast((ra/cos(cast(dec*30 as int)/30.0))*30 as int)/30.0,
cast(dec*30 as int)/30.0
-- now build mask grid.
-- This is a separate query if no temp tables can be made
SELECT cast((ra/cos(cast(dec*30 as int)/30.0))*30 as int)/30.0 as raCosDec,
cast(dec*30 as int)/30.0 as dec,
count(*) as pop
FROM PhotoObj as PO
JOIN dbo.fHTMCoverRegion('CHULL J2000 179 -1 179 1 181 1 181 -1') AS T
ON PO.htmID BETWEEN T.HTMIDstart AND T.HTMIDend
JOIN PhotoType as PT ON PO.type = PT.value
WHERE
ra between 179 and 181
and dec between -1 and 1
and PT.name in ('COSMIC_RAY', 'DEFECT', 'GHOST', 'TRAIL', 'UNKNOWN')
GROUP BY cast((ra/cos(cast(dec*30 as int)/30.0))*30 as int)/30.0,
cast(dec*30 as int)/30.0 </textarea><textarea style="display:none" id="q_30651545">-- Create a count of galaxies for each of the HTM triangles.
-- Galaxies should satisfy a certain color cut,
-- like 0.7u-0.5g-0.2i<1.25 && r<21.75, output it in a form
-- adequate for visualization.
SELECT (htmID / power(2,24)) as htm_8 ,
-- group by 8-deep HTMID (rshift HTM by 12)
avg(ra) as ra,
avg(dec) as [dec],
count(*) as pop -- return center point and count for display
FROM Galaxy -- only look at galaxies
WHERE (0.7*u - 0.5*g - 0.2*i) < 1.25 -- meeting this color cut
and r < 21.75 -- brighter than 21.75 magnitude in red band.
group by (htmID /power(2,24)) -- group into 8-deep HTM buckets.
</textarea><textarea style="display:none" id="q_598412421">-- Find stars with multiple measurements with magnitude variations >0.1.
-- Note that this runs very slowly unless explicit workarounds are included
-- for some SQLServer Optimizer bugs, which are NOT included here
SELECT TOP 100
S1.objID as objID1, S2.objID as ObjID2 -- select object IDs of star and its pair
FROM Star as S1, -- the primary star
photoObj as S2, -- the second observation of the star
neighbors as N -- the neighbor record
WHERE S1.objID = N.objID -- insist the stars are neighbors
and S2.objID = N.neighborObjID -- using precomputed neighbors table
and distance < 0.5/60 -- distance is 0.5 arc second or less
and S1.run != S2.run -- observations are two different runs
and S2.type = dbo.fPhotoType('Star') -- S2 is indeed a star
and S1.u between 1 and 27 -- S1 magnitudes are reasonable
and S1.g between 1 and 27
and S1.r between 1 and 27
and S1.i between 1 and 27
and S1.z between 1 and 27
and S2.u between 1 and 27 -- S2 magnitudes are reasonable.
and S2.g between 1 and 27
and S2.r between 1 and 27
and S2.i between 1 and 27
and S2.z between 1 and 27
and ( -- and one of the colors is different.
abs(S1.u-S2.u) > .1 + (abs(S1.Err_u) + abs(S2.Err_u))
or abs(S1.g-S2.g) > .1 + (abs(S1.Err_g) + abs(S2.Err_g))
or abs(S1.r-S2.r) > .1 + (abs(S1.Err_r) + abs(S2.Err_r))
or abs(S1.i-S2.i) > .1 + (abs(S1.Err_i) + abs(S2.Err_i))
or abs(S1.z-S2.z) > .1 + (abs(S1.Err_z) + abs(S2.Err_z))
)
</textarea><textarea style="display:none" id="q_834106047">-- This query uses the new SQL Server 2005 CROSS APPLY and OUTER APPLY
-- constructs to apply a table-valued function to the results of a query.
-- In this example, we use the fFootPrintEq function which returns a list
-- of SDSS regions that intersect the area specified by the RA, dec and
-- radius, or NULL if the area is outside the SDSS footprint.
-- For each point in the input list, in this case the result of a query
-- on PhotoObj, return "yes" or "no" depending on whether the point is in
-- the SDSS footprint or not, and any other needed columns.
SELECT top 100 objID, ra, dec,
(case when p.type is null then 'NO' else 'YES' end) as found
FROM PhotoObj AS p
OUTER APPLY dbo.fFootprintEq(ra,dec,0.1)
WHERE (ra between 179.5 and 182.3) and (dec between -1.0 and 1.8)
</textarea>
<textarea style="display:none" id="q_190266330">-- Basic_SELECT_FROM_WHERE
-- Find objects in a particular field.
SELECT objID,
field, ra, dec -- Get the unique object ID, field number, and coords
FROM PhotoObj -- From the photometric data
WHERE fieldID = 587722951961673728 -- that is in a specific field
</textarea><textarea style="display:none" id="q_399748022">-- Galaxies meeting two simple criteria.
-- Find all galaxies brighter than r magnitude 17, where the local
-- extinction is > 0.275. This is a simple query that uses a WHERE clause,
-- but now two conditions that must be met simultaneously.
--
-- Finds 6604 galaxies in under 10 mins on DR2, but beware that increasing
-- the limiting r magnitude will significantly add to the execution time.
SELECT objID
FROM Galaxy
WHERE
r < 17 -- r IS NOT deredenned
and extinction_r > 0.275 -- extinction more than 0.175
</textarea><textarea style="display:none" id="q_168487273">-- Find all objects with unclassified spectra.
-- A simple SELECT-FROM-WHERE query, using a function
--
-- On DR2, returns 3109 rows in 20 sec.
SELECT specObjID
FROM SpecObj
WHERE SpecClass = dbo.fSpecClass('UNKNOWN')</textarea><textarea style="display:none" id="q_1315505534">-- Galaxies meeting multiple simple criteria.
-- Find all galaxies with blue surface brightness between 23 and 25
-- mag per square arcseconds, and -10 < supergalactic latitude (sgb) < 10, and
-- declination less than zero. Currently, we have to live with ra/dec until we
-- get galactic coordinates. To calculate surface brightness per sq. arcsec,
-- we use (g + rho), where g is the blue magnitude, and rho= 5*log(r). This
-- query now has three requirements, one involving simple math.
--
-- On DR2, returns 61090 rows in 330 sec.
SELECT objID
FROM Galaxy
WHERE ra between 178 and 180
and dec < 0
-- and (g+rho) between 23 and 25
and g between (23-rho) and (25-rho)
-- g is the blue magnitude, and rho= 5*log(Petro radius)</textarea><textarea style="display:none" id="q_1675888762">-- Using spatial unit vectors for coordinate cuts.
-- Find galaxies in a given area of the sky, using a coordinate cut
-- in the unit vector cx,cy,cz that corresponds to a specific RA range.
-- Another simple query that uses math in the WHERE clause.
--
-- Finds 100 galaxies in 230 sec on DR2, but this is a very slow way to do
-- coordinate cuts. Using RA/dec is *much* faster due to indexing.
--
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT TOP 100 colc_g, colc_r
FROM Galaxy
WHERE
(-0.466 * cx + 0.689 * cy>=0)
and (-0.385 * cx - 0.173 * cy <0)
</textarea><textarea style="display:none" id="q_1650901083">-- Find CVs using colors.
-- Search for Cataclysmic Variables and pre-CVs with White Dwarfs and
-- very late secondaries. Just uses some simple color cuts from Paula Szkody.
-- Another simple query that uses math in the WHERE clause
--
-- Finishes in 72 sec on DR2.
SELECT TOP 10000 run,
camCol,
rerun,
field,
objID,
u, g, r, i, z,
ra, dec -- Just get some basic quantities
FROM PhotoPrimary -- From all primary detections, regardless of class
WHERE u - g < 0.4
and g - r < 0.7
and r - i > 0.4
and i - z > 0.4 -- that meet the color criteria
</textarea><textarea style="display:none" id="q_763893289">-- Getting a subsample of the data.
-- Uses the integer short object id (obj) and the '%' syntax (like awk)
-- to get every 1000th object. THIS IS NOT A TRULY RANDOM SUBSET!
--
-- Returns 11367 objects in DR2 (in about 10-15mins).
SELECT u, g, r, i, z
FROM Galaxy with (nolock)
WHERE (objID%1000) = 1
AND (r between 18 and 21)
</textarea><textarea style="display:none" id="q_1725633998">-- Low-z QSO candidates using color cuts.
-- from Gordon Richards.
-- Also a simple query with a long WHERE clause.
SELECT TOP 1000 g, run, rerun, camcol, field, objID
FROM
Galaxy
WHERE (
(g <= 22) and
(u-g >= -0.27) and (u-g < 0.71) and
(g-r >= -0.24) and (g-r < 0.35) and
(r-i >= -0.27) and (r-i < 0.57) and
(i-z >= -0.35) and (i-z < 0.70)
)</textarea><textarea style="display:none" id="q_1178472613">-- Get object velocities and errors.
-- This is also a simple query that uses a WHERE clause.
-- However, now we perform a more complex mathematical operation.
SELECT TOP 1000
run, -- get a bunch of quantities
camCol,
field,
objID,
rowC, colC, rowV, colV, rowVErr, colVErr,
flags,
psfMag_u, psfMag_g, psfMag_r, psfMag_i, psfMag_z,
psfMagErr_u, psfMagErr_g, psfMagErr_r, psfMagErr_i, psfMagErr_z
FROM PhotoPrimary
WHERE ((rowv * rowv) / (rowvErr * rowvErr) +
(colv * colv) / (colvErr * colvErr) > 4)
-- where the velocities are reliable
</textarea><textarea style="display:none" id="q_828709702">-- Using the BETWEEN syntax.
-- Find galaxies with an isophotal surface brightness (SB) larger
-- than 24 in the red band, and with an ellipticity > 0.5, and with the major
-- axis of the ellipse having a declination between 30" and 60" arc seconds.
-- This is also a simple query that uses a WHERE clause with three conditions
-- that must be met. We introduce the syntax 'BETWEEN' to do a range search.
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT TOP 100 ObjID
FROM Galaxy
WHERE r < 24 - rho
-- surface brightness brighter than 24 mag. per sq. arcsec in the red
-- Note that isolating r (indexed) on one side helps this run faster
and isoA_r between 30 and 60
-- major axis between 30" and 60"
and (power(q_r,2) + power(u_r,2)) > 0.25
-- square of ellipticity is > 0.5 squared. The SQL term 'power' is used for exponentiation.</textarea><textarea style="display:none" id="q_1055252390">-- Moving objects consistent with an asteroid.
-- Also a simple query, but we introduce the 'as' syntax, which allows us to
-- name derived quantities in the result file.
--
--This Sample Query will not work for SDSS3 contexts
SELECT TOP 10
objID,
sqrt( power(rowv,2) + power(colv, 2) ) as velocity
FROM PhotoObj
WHERE
(power(rowv,2) + power(colv, 2)) between 50 and 1000
</textarea><textarea style="display:none" id="q_791936939">-- Find quasars in imaging data.
-- as specified by Xiaohui Fan et.al.
-- A rather straightforward query, just with many conditions.
SELECT TOP 1000 run,
camCol,
rerun,
field,
objID,
u, g, r, i, z,
ra, dec
FROM Star -- or Galaxy
WHERE ( u - g > 2.0 or u > 22.3 )
and ( i < 19 )
and ( i > 0 )
and ( g - r > 1.0 )
and ( r - i <
(0.08 + 0.42 * (g - r - 0.96) )
or g - r > 2.26 )
and ( i - z < 0.25 )
</textarea><textarea style="display:none" id="q_224126374">-- Using object counting and logic in a query.
-- Find all objects similar to the colors of a quasar at 5.5<redshift<6.5.
SELECT count(*) as 'total',
sum( case when (Type=3) then 1 else 0 end) as 'Galaxies',
sum( case when (Type=6) then 1 else 0 end) as 'Stars',
sum( case when (Type not in (3,6)) then 1 else 0 end) as 'Other'
FROM PhotoPrimary -- for each object
WHERE (( u - g > 2.0) or (u > 22.3) ) -- apply the quasar color cut.
and ( i between 0 and 19 )
and ( g - r > 1.0 )
and ( (r - i < 0.08 + 0.42 * (g - r - 0.96)) or (g - r > 2.26 ) )
and ( i - z < 0.25 )
</textarea><textarea style="display:none" id="q_388139904">-- Find galaxies that are blended with a star.
-- Output the deblended galaxy magnitudes.
-- This query introduces the use of multiple tables or views. You can assign
-- nicknames to tables as in the FROM clause below. Since you are using
-- multiple tables, you ,ust specify which table each quantity in the SELECT
-- clause comes from. Finally, the last line in the query is the join between
-- the two tables, which is achieved by requiring that a quantity present in
-- both tables be equal.
-- NOTE: This query times out (takes too long) without the "TOP 1000".
SELECT top 1000 G.ObjID, G.u, G.g, G.r, G.i, G.z --get the ObjID and final mags
FROM Galaxy G, Star S -- use two Views, Galaxy and Star, as a convenient mechanism to compare objects
WHERE G.parentID > 0 -- galaxy has a "parent", which tells us this object was deblended
and G.parentID = S.parentID -- and the star has the same parent
</textarea><textarea style="display:none" id="q_915208631">-- Stars selected using Field criteria.
-- Give me the PSF colors of all stars brighter than g=20 that have PSP_STATUS = 2.
-- Another simple multi-table query.
SELECT TOP 1000
s.psfMag_g, -- or whatever you want from each object
s.run,
s.camCol,
s.rerun,
s.field
FROM Star s, Field f
WHERE s.fieldID = f.fieldID
and s.psfMag_g < 20
and f.pspStatus = 2</textarea><textarea style="display:none" id="q_98652983">-- Objects selected by cuts on three tables.
-- Find the parameters for all objects in a selected field with
-- desired PSF width and range of columns.
-- Now we are using three tables, but it is still a simple query.
-- NOTE: This query times out (takes too long) without the "TOP 1000".
SELECT TOP 1000
f.run,
f.rerun,
f.camCol,
f.field,
p.objID,
p.ra,
p.dec,
p.Rowc,
p.Colc,
p.u,
p.modelMagErr_u ,
p.g,
p.modelMagErr_g,
p.r,
p.modelMagErr_r,
p.petroMag_r - p.extinction_r,
p.petroMagErr_r,
p.i,
p.modelMagErr_i,
p.z,
f.psfWidth_r
FROM
photoObj p, field f
WHERE
f.fieldid = p.fieldid
and f.psfWidth_r > 1.2
and p.colc > 400.0
</textarea><textarea style="display:none" id="q_2027172584">-- Find all objects within 30 arcseconds of one another
-- that have very similar colors: that is where the color ratios
-- u-g, g-r, r-I are less than 0.05m.
SELECT TOP 10 P.ObjID -- distinct cases
FROM PhotoPrimary P, -- P is the primary object
Neighbors N, -- N is the neighbor link
PhotoPrimary L -- L is the lens candidate of P
WHERE P.ObjID = N.ObjID -- N is a neighbor record
and L.ObjID = N.NeighborObjID -- L is a neighbor of P
and P.ObjID < L. ObjID -- avoid duplicates
and abs((P.u-P.g)-(L.u-L.g))<0.05 -- L and P have similar spectra.
and abs((P.g-P.r)-(L.g-L.r))<0.05
and abs((P.r-P.i)-(L.r-L.i))<0.05
and abs((P.i-P.z)-(L.i-L.z))<0.05
</textarea><textarea style="display:none" id="q_730255691">-- Find specific types of quasars using spectroscopy.
-- The easiest way to find quasars is by finding objects whose spectra have
-- been classified as quasars. This sample query searches the SpecObj
-- table for the IDs and redshifts of objects with the class column equal to 'QSO'
SELECT TOP 100 specObjID, z
FROM SpecObj
WHERE class = 'QSO' AND zWarning = 0
</textarea><textarea style="display:none" id="q_1691326363">-- Checking for errors using flags.
-- Another useful query is to see if the errors on moving (or
-- apparently moving) objects are correct. For example, it used to be that
-- some known QSOs were being flagged as moving objects. One way to look for
-- such objects is to compare the velocity to the error in velocity and see if
-- the "OBJECT1_MOVED" or "OBJECT2_BAD_MOVING_FIT" is set.
-- This query introduces bitwise logic for flags, and uses the 'as' syntax to
-- make the query more readable. Note that if a flag is not set, the value
-- will be zero. If you want to ensure multiple flags are not set, you can
-- either check that each individually is zero, or their sum is zero.
-- (From Gordon Richards)
SELECT TOP 1000
run,
rerun,
camcol,
field,
objID,
ra, dec,
rowv, colv,
rowvErr, colvErr,
i,
(flags & dbo.fPhotoFlags('MOVED')) as MOVED,
(flags & dbo.fPhotoFlags('BAD_MOVING_FIT')) as BAD_MOVING_FIT
FROM Galaxy
WHERE
(flags & (dbo.fPhotoFlags('MOVED') + dbo.fPhotoFlags('BAD_MOVING_FIT'))) > 0
and (rowv * rowv + colv * colv) >=
(rowvErr * rowvErr + colvErr * colvErr)</textarea><textarea style="display:none" id="q_1324808024">-- Elliptical galaxies based on model fits.
-- Find all galaxies with a deVaucouleours profile and the
-- photometric colors consistent with an elliptical galaxy. NOTE THAT THE
-- NAMES and VALUES OF THE LIKELIHOODS HAVE CHANGED SINCE THE EDR; they are
-- now log likelihoods, and named accordingly (lDev is now lnlDev, etc.) to
-- indicate these are log likelihoods. This query has many conditions, and
-- also has the use of bitwise logic necessary for dealing with flags.
SELECT TOP 100 ObjID
FROM Galaxy as G
WHERE
G.lnlDev_r > G.lnlExp_r + 0.1
-- the likelihood of the deVaucouleours profile fit is 10% greater than the likelihood of the exponential fit
and G.lnlExp_r > -999
-- and the likelihoods are actually meaningful
and (G.flags & (dbo.fPhotoFlags('BINNED1') + dbo.fPhotoFlags('BINNED2') + dbo.fPhotoFlags('BINNED4'))) > 0
--and it is detected from at least one of the binned images ???
and (G.flags & ( dbo.fPhotoFlags('BLENDED') + dbo.fPhotoFlags('NODEBLEND') + dbo.fPhotoFlags('CHILD'))) != dbo.fPhotoFlags('BLENDED')
--and, if it is blended, it is either a child or not deblended further ??
and (G.flags & (dbo.fPhotoFlags('EDGE') + dbo.fPhotoFlags('SATURATED'))) = 0
-- and it is not near a ccd edge or saturated, where measurements may be bad
and G.petroMag_i > 17.5
-- and it is fainter than 17.5 in i-band
and (G.petroMag_r > 15.5 or G.petror50_r > 2)
and (G.petroMag_r > 0 and G.g > 0 and G.r > 0 and G.i > 0)
and ( (G.petroMag_r - G.extinction_r) < 19.2
and (G.petroMag_r - G.extinction_r <
(13.1 + (7/3)*(G.g - G.r) + 4 *(G.r - G.i) - 4 * 0.18 ) )
and ( (G.r - G.i - (G.g - G.r)/4 - 0.18) < 0.2 )
and ( (G.r - G.i - (G.g - G.r)/4 - 0.18) > -0.2 ) )
or ( (G.petroMag_r - G.extinction_r < 19.5)
and ( (G.r - G.i - (G.g - G.r)/4 - 0.18) >
(0.45 - 4*(G.g - G.r) ) )
and ( (G.g - G.r) > (1.35 + 0.25 *(G.r - G.i) ) ) )
-- and many constraints on colors and mags are met to make it have
-- elliptical-type colors.
</textarea><textarea style="display:none" id="q_51406064">-- Galaxies with bluer centers.
-- by Michael Strauss. For all galaxies
-- with r_Petro < 18, not saturated, not bright, and not edge, give me those
-- with centers appreciably bluer than their outer parts, i.e., define the
-- center color as: u_psf - g_psf and define the outer color as: u_model -
-- g_model; give me all objs which have (u_model - g_model) - (u_psf - g_psf)
-- < -0.4
-- Another flags-based query.
SELECT TOP 1000
colc_u, colc_g, objID
FROM Galaxy
WHERE
( Flags & (dbo.fPhotoFlags('SATURATED') +
dbo.fPhotoFlags('BRIGHT') +
dbo.fPhotoFlags('EDGE')) ) = 0
and petrorad_r < 18
and ((colc_u - colc_g) - (psfMag_u - psfMag_g)) < -0.4</textarea><textarea style="display:none" id="q_1713458572">-- Diameter-limited sample of galaxies
-- from James Annis.
SELECT TOP 1000
run,
camCol,
rerun,
field,
objID,
ra,
dec
FROM Galaxy
WHERE ( flags & (dbo.fPhotoFlags('BINNED1')
+ dbo.fPhotoFlags('BINNED2')
+ dbo.fPhotoFlags('BINNED4')) ) > 0
and ( flags & (dbo.fPhotoFlags('BLENDED')
+ dbo.fPhotoFlags('NODEBLEND')
+ dbo.fPhotoFlags('CHILD')) ) != dbo.fPhotoFlags('BLENDED')
and ( ( (flags & dbo.fPhotoFlags('NOPETRO') = 0)
and petrorad_i > 15)
or ( (flags & dbo.fPhotoFlags('NOPETRO') > 0)
and petrorad_i > 7.5)
or ( (flags & dbo.fPhotoFlags('TOO_LARGE') > 0)
and petrorad_i > 2.5)
or
( (flags & dbo.fPhotoFlags('SATURATED') = 0)
and petrorad_i > 17.5) )
</textarea><textarea style="display:none" id="q_70783942">-- Extremely red galaxies.
-- from James Annis.
-- Similar to the diameter limited sample query.
SELECT TOP 1000
g.run,
g.camCol,
g.rerun,
g.field,
g.objID,
g.ra, g.dec
FROM Field f, Galaxy g
WHERE
g.fieldID = f.fieldID
and ( g.flags & (dbo.fPhotoFlags('BINNED1')
+ dbo.fPhotoFlags('BINNED2')
+ dbo.fPhotoFlags('BINNED4')) ) > 0
and ( g.flags & (dbo.fPhotoFlags('BLENDED')
+ dbo.fPhotoFlags('NODEBLEND')
+ dbo.fPhotoFlags('CHILD')) ) != dbo.fPhotoFlags('BLENDED')
and ( g.flags & (dbo.fPhotoFlags('COSMIC_RAY')
+ dbo.fPhotoFlags('INTERP')) ) = 0
and f.psfWidth_r < 1.5
and (g.i - g.z > 1.0 ) -- i and z in primary tables DO NOT include extinction</textarea><textarea style="display:none" id="q_1804705991">-- A version of the LRG sample.
-- by James Annis.
-- Another query with many conditions and flag tests.
SELECT TOP 100
run,
camCol,
rerun,
field,
objID,
ra,
dec
FROM Galaxy
WHERE ( ( flags & (dbo.fPhotoFlags('BINNED1')
+ dbo.fPhotoFlags('BINNED2')
+ dbo.fPhotoFlags('BINNED4')) ) > 0
and ( flags & (dbo.fPhotoFlags('BLENDED')
+ dbo.fPhotoFlags('NODEBLEND')
+ dbo.fPhotoFlags('CHILD')) ) != dbo.fPhotoFlags('BLENDED')
and ( flags & (dbo.fPhotoFlags('EDGE')
+ dbo.fPhotoFlags('SATURATED')) ) = 0
and petroMag_i > 17.5
and (petroMag_r > 15.5 or petror50_r > 2)
and (petroMag_r > 0 and g > 0 and r > 0 and i > 0)
and ( (petroMag_r-extinction_r) < 19.2
and (petroMag_r - extinction_r <
(13.1 + (7/3) * (dered_g - dered_r) + 4 * (dered_r - dered_i) - 4 * 0.18) )
and ( (dered_r - dered_i - (dered_g - dered_r)/4 - 0.18) < 0.2)
and ( (dered_r - dered_i - (dered_g - dered_r)/4 - 0.18) > -0.2)
--dered_ quantities already include extinction
and ( (petroMag_r - extinction_r +
2.5 * LOG10(2 * 3.1415 * petror50_r * petror50_r)) < 24.2) )
or ( (petroMag_r - extinction_r < 19.5)
and ( (dered_r - dered_i - (dered_g - dered_r)/4 - 0.18) > (0.45 - 4 * (dered_g - dered_r)) )
and ( (dered_g - dered_r) > (1.35 + 0.25 * (dered_r - dered_i)) ) )
and ( (petroMag_r - extinction_r +
2.5 * LOG10(2 * 3.1415 * petror50_r * petror50_r) ) < 23.3 ) )</textarea><textarea style="display:none" id="q_167002323">-- Find galaxies with specific spectra.
-- Namely, they have an equivalent width in
-- H_alpha > 40 Angstroms. We want object ID's from the photometry (Galaxy)
-- but constraints from spectroscopy. The line widths and IDs are stored in
-- SpecLine. --This is a simple query, but now we are using three tables. The
-- spectroscopy tables of measured lines are arranged non-intuitively, and we
-- urge users to read about them on the DAS help pages. --IMPORTANT NOTE:
-- Each spectroscopic object now has a match to at least two photometric
-- objects, one in Target and one in Best. Therefore, when performing a join
-- between spectroscopic photometric objects, you must specify either
-- PhotoObj.ObjID=SpecObj.bestObjID or PhotoObj.ObjID = SpecObj.targetObjID.
-- Normally, the default photometric database is BEST, so you will want to use
-- SpecObj.bestObjID
--
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT G.ObjID -- we want the photometric ObjID
FROM Galaxy as G, -- G is the galaxy
SpecObj as S, -- S is the spectra of galaxy G
SpecLine as L, -- L is a line of S
SpecLineNames as LN -- the names of the lines
WHERE G.ObjID = S.bestObjID -- connect the galaxy to the spectrum
and S.SpecObjID = L.SpecObjID -- and the spectral line L is detected in the spectrum
and L.LineId = LN.value -- L is the H alpha line
and LN.name = 'Ha_6565'
and L.ew > 40 -- and H alpha is at least 40 angstroms wide.
</textarea><textarea style="display:none" id="q_834596942">-- Find galaxies with more specific spectra.
-- Same as prior query, but also require weak Hbeta line (Halpha/Hbeta > 20.)
--
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT G.ObjID -- return qualifying galaxies
FROM Galaxy as G, -- G is the galaxy
SpecObj as S, -- S is the spectra of galaxy G
SpecLine as L1, -- L1 is a line of S
SpecLine as L2, -- L2 is a second line of S
specLineNames as LN1, -- the names of the lines (Halpha)
specLineNames as LN2 -- the names of the lines (Hbeta)
WHERE G.ObjID = S.BestObjID -- connect the galaxy to the spectrum
and S.SpecObjID = L1.SpecObjID -- L1 is a line of S.
and S.SpecObjID = L2.SpecObjID -- L2 is a line of S.
and L1.LineId = LN1. value
and LN1.name = 'Ha_6565' -- L1 is the H alpha line
and L2.LineId = LN2.value -- L2 is the H alpha line
and LN2.name = 'Hb_4863' --
and L1.ew > 200 -- BIG Halpha
and L2.ew > 10 -- significant Hbeta emission line
and L2.ew * 20 < L1.ew -- Hbeta is comparatively small
</textarea><textarea style="display:none" id="q_1424444742">-- Find binary stars with specific colors.
-- At least one of them should have the colors of a white dwarf.
SELECT TOP 100 s1.objID as s1, s2.objID as s2
FROM Star S1, -- S1 is the white dwarf
Neighbors N, -- N is the precomputed neighbors links
Star S2 -- S2 is the second star
WHERE S1.objID = N. objID -- S1 and S2 are neighbors-within 30 arc sec
and S2.objID = N.NeighborObjID
and N.neighborType = dbo.fPhotoType('Star') -- and S2 is a star
and N.distance < .05 -- the 3 arcsecond test
and ((S1.u - S1.g) < 0.4 ) -- and S1 meets Paul Szkodys color cut for
and (S1.g - S1.r) < 0.7 -- white dwarfs.
and (S1.r - S1.i) > 0.4
and (S1.i - S1.z) > 0.4
</textarea><textarea style="display:none" id="q_175511087">-- Find quasars with a broad absorption line and a nearby galaxy.
-- within 10 arcseconds.
-- Return both the quasars and the galaxies.
--
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT Q.BestObjID as Quasar_candidate_ID , G.ObjID as Galaxy_ID, N.distance
FROM SpecObj as Q, -- Q is the specObj of the quasar candidate
Neighbors as N, -- N is the Neighbors list of Q
Galaxy as G, -- G is the nearby galaxy
SpecClass as SC, -- Spec Class
SpecLine as L, -- L is the broad line we are looking for
SpecLineNames as LN -- Line Name
WHERE Q.SpecClass =SC.value -- Q is a QSO
and SC.name in ('QSO', 'HIZ_QSO') -- Spectrum says "QSO"
and Q.SpecObjID = L.SpecObjID -- L is a spectral line of Q.
and L.LineID = LN.value -- line found and
and LN.Name != 'UNKNOWN' -- not not identified
and L.ew < -10 -- but its a prominent absorption line
and Q.BestObjID = N.ObjID -- N is a neighbor record
and G.ObjID = N.NeighborObjID -- G is a neighbor of Q
and N.distance < 10.0/60 -- and it is within 10 arcseconds of the Q.
</textarea><textarea style="display:none" id="q_1053909050">-- Find galaxies without saturated pixels within 1' of a given point.
-- ra=185.0, dec=-0.5. This query uses a function fGetNearbyObjEq,
-- which takes 3 arguments (ra,dec, distance in arcmin); this function uses
-- the Neighbors table. The Neighbors table and the Galaxy table have in
-- common the objID, so we have to select objects from both where the objIDs
-- are the same. The output of the function is a table with the Galaxy Object
-- ID and distance in arcmin from the input. This query introduces the use of
-- a JOIN to combine table contents. Also, we use the 'orDER BY' syntax,
-- which will sort the output.
SELECT TOP 100 G.objID, GN.distance
FROM Galaxy as G
JOIN dbo.fGetNearbyObjEq(185.,-0.5, 1) as GN -- this function outputs a table, so we have to do a join
on G.objID = GN.objID -- get objects from temporary neighbors table GN with desired ObjID
WHERE (G.flags & dbo.fPhotoFlags('saturated')) = 0 -- and the object is not saturated. f.PhotoFlags is a function that interprets the flag bits.
ORDER BY distance -- sort these by distance
</textarea><textarea style="display:none" id="q_622853371">-- Ellipticals with odd lines.
-- Find all elliptical galaxies with spectra that have an anomalous
-- emission line. This query introduces the SQL syntax DISTINCT, which will
-- return only one instance of the requested parameter (ObjID, in this case),
-- because our query may return the same object more than once. This is also
-- the first nested query, where we use one SELECT (the inner one) to get a
-- group of objects we are not interested in. The outer SELECT includes the
-- new syntax 'not in', which is used to perform the exclusion.
--
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT DISTINCT G.ObjID -- return qualifying galaxies
FROM
Galaxy as G, -- G is the galaxy
SpecObjAll as S, -- S is the spectra of galaxy G
SpecLineAll as L, -- L is a line of S
-- we must use SpecLineAll because SpecLine only has ID's lines
XCRedshift as XC -- the template cross-correlation redshift
WHERE G.ObjID = S.bestObjID -- connect galaxy to the spectrum
and S.SpecObjID = L.SpecObjID -- The line L must be in the spectrum S
and S.SpecObjID = XC.SpecObjID -- and there is a crosscorrelation redshift
and XC.tempNo = 8 -- Template('Elliptical') -- best Cross correlation template used is "elliptical"
and L.LineID = 0
and L.ew > 10 -- and the line is prominent by some definition, in this case, the equivalent width is over 10 Angstroms
and S.SpecObjID not in (
-- insist that there are no other lines
SELECT S.SpecObjID -- This is the chosen line.
FROM SpecLine as L1 -- L1 is another line...
-- by using SpecLine, we are automatically requiring that the line
-- be identified
WHERE S.SpecObjID = L1.SpecObjID -- ...for this object...
and abs(L.wave - L1.wave) <.01
-- ...at nearly the same wavelength...
)
</textarea><textarea style="display:none" id="q_510380354">-- Search near BCG galaxies.
-- For each galaxy in the BCG data set (brightest cluster galaxy),
-- in 160<right ascension<170, -25<declination<35 count the number of
-- galaxies within 30" of it that have a photoz within 0.05
-- of that galaxy.
-- An extremely complex WHERE clause.
SELECT G.objID, count(N.NeighborObjID) as pop
FROM Galaxy as G, -- first gravitational lens candidate
Neighbors as N, -- precomputed list of neighbors
Galaxy as U, -- a neighbor galaxy of G
photoZ as Gpz, -- photoZ of G.
photoZ as Npz -- Neighbor photoZ
WHERE G.ra between 160 and 170
and G.dec between -5 and 5
and G.objID = N.objID -- connect G and U via the neighbors table
and U.objID = N.neighborObjID -- so that we know G and U are within
and N.objID < N.neighborObjID -- 30 arcseconds of one another.
and G.objID = Gpz.objID
and U.objID = Npz.objID
and abs(Gpz.Z - Npz.Z) < 0.05 -- restrict the photoZ differences
and (G.flags & (dbo.fPhotoFlags('BINNED1') + dbo.fPhotoFlags('BINNED2') + dbo.fPhotoFlags('BINNED4'))) > 0
--and it is detected from at least one of the binned images
and (G.flags & ( dbo.fPhotoFlags('BLENDED') + dbo.fPhotoFlags('NODEBLEND') + dbo.fPhotoFlags('CHILD'))) != dbo.fPhotoFlags('BLENDED')
--and, if it is blended, it is either a child or not deblended further ??
and (G.flags & (dbo.fPhotoFlags('EDGE') + dbo.fPhotoFlags('SATURATED'))) = 0
-- and it is not near a ccd edge or saturated, where measurements may be bad
-- and apply color cut for a BCG courtesy of James Annis of Fermilab
and G.petroMag_i > 17.5
and (G.petroMag_r > 15.5 or G.petror50_r > 2)
and (G.petroMag_r < 30 and G.g < 30 and G.r < 30 and G.i < 30)
and (G.r < 19.2
and ( 1=1 or -- huh?
(G.r < (13.1 + (7/3)*(G.g - G.r) +
-- deRed_r < 13.1 + 0.7 / 0.3 * deRed_gr
4 *(G.r - G.i - 0.18 ))
-- 1.2 / 0.3 * deRed_ri
and (( G.r - G.i - (G.g - G.r)/4 - 0.18) BETWEEN -0.2 and 0.2 )
and ((G.r +
-- petSB - deRed_r + 2.5 log10(2Pi*petror50^2)
2.5 * LOG( 2 * 3.1415 * G.petror50_r * G.petror50_r )) < 24.2 )
)
or
( (G.r < 19.5 )
and (( G.r - G.i -(G.g - G.r)/4 -.18) >
-- - deRed_gr/4 - 0.18
-- cperp = deRed_ri
(0.45 - 4*( G.g - G.r)))
-- 0.45 - deRed_gr/0.25
and ((G.g - G.r) > ( 1.35 + 0.25 *(G.r - G.i)))
and ((G.r +
-- petSB - deRed_r + 2.5 log10(2Pi*petror50^2)
2.5 * LOG( 2 * 3.1415 * G.petror50_r * G.petror50_r )) < 23.3 )
)) )
group by G.objID
</textarea><textarea style="display:none" id="q_963813061">-- Broadest line of each spectrum with its ID.
-- (or more generally, all the columns for
-- the spectral line with the highest/lowest something)? The line width is
-- stored in the column sigma, the identification is in the column restwave.
-- (Sebastian Jester )
--
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT
L.specObjId,
L.specLineID,
sMax.Maxwidth -- get the spectroscopic object ID, the line ID, and the width
FROM specLine L,
(SELECT specObjID,
Max(waveMax-waveMin) as MaxWidth
-- Define MaxWidth as the largest difference in the min and max wavelength of
-- an identified line, using the built-in Max function of SQL
FROM SpecLine
GROUP BY specObjID) as sMax
-- sMax contains a single specObjID and MaxWidth. Remember that for each line
-- identified in a given object's spectrum, there is an entry in
-- SpecLine. This means that each specObjID appears many times in SpecLine,
-- once for each line found, and they must be aggregated before performing any
-- operation such as Max. The GROUP BY is thus NECESSARY.
-- The upper FROM clause is telling us we will use the table SpecLine and this
-- new output called sMax, which contains one entry with the SpecObjID and
-- MaxWidth. If we used some other function instead of 'Max', such as 'top
-- 10', sMax would have more than row.
WHERE
L.specObjID = sMax.specObjID
and (L.waveMax-L.waveMin) = sMax.MaxWidth
-- Just as with the specObjID, each specLineID appears many times in specLine.
-- This final WHERE clause makes sure we get the one specLineID from SpecObj
-- which matches the unique combination of specObjID and MaxWidth in sMax.
</textarea><textarea style="display:none" id="q_23925016">-- Gridded galaxy counts and masks. Actually consists of TWO queries:
-- 1) Create a gridded count of galaxies with u-g > 1 and r < 21.5 over -1 < dec < 1,
-- and 179 < R.A. < 181, on a grid, and create a map of masks over the same grid.
-- Scan the table for galaxies and group them in cells 2 arc-minuteson a side. Provide
-- predicates for the color restrictions on u-g and r and to limit the search to the
-- portion of the sky defined by the right ascension and declination conditions. Return
-- the count of qualifying galaxies in each cell.
-- 2) Run another query with the same grouping, but with a predicate to include only
-- objects such as satellites, planets, and airplanes that obscure the cell. The second
-- query returns a list of cell coordinates that serve as a mask for the first query.
--- First find the gridded galaxy count (with the color cut)
--- In local tangent plane, ra/cos(dec) is a linear degree.
SELECT cast((ra/cos(cast(dec*30 as int)/30.0))*30 as int)/30.0 as raCosDec,
cast(dec*30 as int)/30.0 as dec,
count(*) as pop
FROM Galaxy as G
JOIN dbo.fHTMCoverRegion('CHULL J2000 179 -1 179 1 181 1 181 -1') AS T
ON G.htmID BETWEEN T.HTMIDstart AND T. HTMIDend
WHERE ra between 179 and 181
and dec between -1 and 1
and u-g > 1
and r < 21.5
GROUP BY cast((ra/cos(cast(dec*30 as int)/30.0))*30 as int)/30.0,
cast(dec*30 as int)/30.0
-- now build mask grid.
-- This is a separate query if no temp tables can be made
SELECT cast((ra/cos(cast(dec*30 as int)/30.0))*30 as int)/30.0 as raCosDec,
cast(dec*30 as int)/30.0 as dec,
count(*) as pop
FROM PhotoObj as PO
JOIN dbo.fHTMCoverRegion('CHULL J2000 179 -1 179 1 181 1 181 -1') AS T
ON PO.htmID BETWEEN T.HTMIDstart AND T.HTMIDend
JOIN PhotoType as PT ON PO.type = PT.value
WHERE
ra between 179 and 181
and dec between -1 and 1
and PT.name in ('COSMIC_RAY', 'DEFECT', 'GHOST', 'TRAIL', 'UNKNOWN')
GROUP BY cast((ra/cos(cast(dec*30 as int)/30.0))*30 as int)/30.0,
cast(dec*30 as int)/30.0 </textarea><textarea style="display:none" id="q_1398357282">-- Create a count of galaxies for each of the HTM triangles.
-- Galaxies should satisfy a certain color cut,
-- like 0.7u-0.5g-0.2i<1.25 && r<21.75, output it in a form
-- adequate for visualization.
SELECT (htmID / power(2,24)) as htm_8 ,
-- group by 8-deep HTMID (rshift HTM by 12)
avg(ra) as ra,
avg(dec) as [dec],
count(*) as pop -- return center point and count for display
FROM Galaxy -- only look at galaxies
WHERE (0.7*u - 0.5*g - 0.2*i) < 1.25 -- meeting this color cut
and r < 21.75 -- brighter than 21.75 magnitude in red band.
group by (htmID /power(2,24)) -- group into 8-deep HTM buckets.
</textarea><textarea style="display:none" id="q_1944663326">-- Find stars with multiple measurements with magnitude variations >0.1.
-- Note that this runs very slowly unless explicit workarounds are included
-- for some SQLServer Optimizer bugs, which are NOT included here
SELECT TOP 100
S1.objID as objID1, S2.objID as ObjID2 -- select object IDs of star and its pair
FROM Star as S1, -- the primary star
photoObj as S2, -- the second observation of the star
neighbors as N -- the neighbor record
WHERE S1.objID = N.objID -- insist the stars are neighbors
and S2.objID = N.neighborObjID -- using precomputed neighbors table
and distance < 0.5/60 -- distance is 0.5 arc second or less
and S1.run != S2.run -- observations are two different runs
and S2.type = dbo.fPhotoType('Star') -- S2 is indeed a star
and S1.u between 1 and 27 -- S1 magnitudes are reasonable
and S1.g between 1 and 27
and S1.r between 1 and 27
and S1.i between 1 and 27
and S1.z between 1 and 27
and S2.u between 1 and 27 -- S2 magnitudes are reasonable.
and S2.g between 1 and 27
and S2.r between 1 and 27
and S2.i between 1 and 27
and S2.z between 1 and 27
and ( -- and one of the colors is different.
abs(S1.u-S2.u) > .1 + (abs(S1.Err_u) + abs(S2.Err_u))
or abs(S1.g-S2.g) > .1 + (abs(S1.Err_g) + abs(S2.Err_g))
or abs(S1.r-S2.r) > .1 + (abs(S1.Err_r) + abs(S2.Err_r))
or abs(S1.i-S2.i) > .1 + (abs(S1.Err_i) + abs(S2.Err_i))
or abs(S1.z-S2.z) > .1 + (abs(S1.Err_z) + abs(S2.Err_z))
)
</textarea><textarea style="display:none" id="q_166816670">-- This query uses the new SQL Server 2005 CROSS APPLY and OUTER APPLY
-- constructs to apply a table-valued function to the results of a query.
-- In this example, we use the fFootPrintEq function which returns a list
-- of SDSS regions that intersect the area specified by the RA, dec and
-- radius, or NULL if the area is outside the SDSS footprint.
-- For each point in the input list, in this case the result of a query
-- on PhotoObj, return "yes" or "no" depending on whether the point is in
-- the SDSS footprint or not, and any other needed columns.
SELECT top 100 objID, ra, dec,
(case when p.type is null then 'NO' else 'YES' end) as found
FROM PhotoObj AS p
OUTER APPLY dbo.fFootprintEq(ra,dec,0.1)
WHERE (ra between 179.5 and 182.3) and (dec between -1.0 and 1.8)
</textarea>
<textarea style="display:none" id="q_314022943">-- Basic_SELECT_FROM_WHERE
-- Find objects in a particular field.
SELECT objID,
field, ra, dec -- Get the unique object ID, field number, and coords
FROM PhotoObj -- From the photometric data
WHERE fieldID = 587722951961673728 -- that is in a specific field
</textarea><textarea style="display:none" id="q_2121237275">-- Galaxies meeting two simple criteria.
-- Find all galaxies brighter than r magnitude 17, where the local
-- extinction is > 0.275. This is a simple query that uses a WHERE clause,
-- but now two conditions that must be met simultaneously.
--
-- Finds 6604 galaxies in under 10 mins on DR2, but beware that increasing
-- the limiting r magnitude will significantly add to the execution time.
SELECT objID
FROM Galaxy
WHERE
r < 17 -- r IS NOT deredenned
and extinction_r > 0.275 -- extinction more than 0.175
</textarea><textarea style="display:none" id="q_706908036">-- Find all objects with unclassified spectra.
-- A simple SELECT-FROM-WHERE query, using a function
--
-- On DR2, returns 3109 rows in 20 sec.
SELECT specObjID
FROM SpecObj
WHERE SpecClass = dbo.fSpecClass('UNKNOWN')</textarea><textarea style="display:none" id="q_1510674311">-- Galaxies meeting multiple simple criteria.
-- Find all galaxies with blue surface brightness between 23 and 25
-- mag per square arcseconds, and -10 < supergalactic latitude (sgb) < 10, and
-- declination less than zero. Currently, we have to live with ra/dec until we
-- get galactic coordinates. To calculate surface brightness per sq. arcsec,
-- we use (g + rho), where g is the blue magnitude, and rho= 5*log(r). This
-- query now has three requirements, one involving simple math.
--
-- On DR2, returns 61090 rows in 330 sec.
SELECT objID
FROM Galaxy
WHERE ra between 178 and 180
and dec < 0
-- and (g+rho) between 23 and 25
and g between (23-rho) and (25-rho)
-- g is the blue magnitude, and rho= 5*log(Petro radius)</textarea><textarea style="display:none" id="q_342684245">-- Using spatial unit vectors for coordinate cuts.
-- Find galaxies in a given area of the sky, using a coordinate cut
-- in the unit vector cx,cy,cz that corresponds to a specific RA range.
-- Another simple query that uses math in the WHERE clause.
--
-- Finds 100 galaxies in 230 sec on DR2, but this is a very slow way to do
-- coordinate cuts. Using RA/dec is *much* faster due to indexing.
--
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT TOP 100 colc_g, colc_r
FROM Galaxy
WHERE
(-0.466 * cx + 0.689 * cy>=0)
and (-0.385 * cx - 0.173 * cy <0)
</textarea><textarea style="display:none" id="q_1821885322">-- Find CVs using colors.
-- Search for Cataclysmic Variables and pre-CVs with White Dwarfs and
-- very late secondaries. Just uses some simple color cuts from Paula Szkody.
-- Another simple query that uses math in the WHERE clause
--
-- Finishes in 72 sec on DR2.
SELECT TOP 10000 run,
camCol,
rerun,
field,
objID,
u, g, r, i, z,
ra, dec -- Just get some basic quantities
FROM PhotoPrimary -- From all primary detections, regardless of class
WHERE u - g < 0.4
and g - r < 0.7
and r - i > 0.4
and i - z > 0.4 -- that meet the color criteria
</textarea><textarea style="display:none" id="q_654356252">-- Getting a subsample of the data.
-- Uses the integer short object id (obj) and the '%' syntax (like awk)
-- to get every 1000th object. THIS IS NOT A TRULY RANDOM SUBSET!
--
-- Returns 11367 objects in DR2 (in about 10-15mins).
SELECT u, g, r, i, z
FROM Galaxy with (nolock)
WHERE (objID%1000) = 1
AND (r between 18 and 21)
</textarea><textarea style="display:none" id="q_420853709">-- Low-z QSO candidates using color cuts.
-- from Gordon Richards.
-- Also a simple query with a long WHERE clause.
SELECT TOP 1000 g, run, rerun, camcol, field, objID
FROM
Galaxy
WHERE (
(g <= 22) and
(u-g >= -0.27) and (u-g < 0.71) and
(g-r >= -0.24) and (g-r < 0.35) and
(r-i >= -0.27) and (r-i < 0.57) and
(i-z >= -0.35) and (i-z < 0.70)
)</textarea><textarea style="display:none" id="q_631175478">-- Get object velocities and errors.
-- This is also a simple query that uses a WHERE clause.
-- However, now we perform a more complex mathematical operation.
SELECT TOP 1000
run, -- get a bunch of quantities
camCol,
field,
objID,
rowC, colC, rowV, colV, rowVErr, colVErr,
flags,
psfMag_u, psfMag_g, psfMag_r, psfMag_i, psfMag_z,
psfMagErr_u, psfMagErr_g, psfMagErr_r, psfMagErr_i, psfMagErr_z
FROM PhotoPrimary
WHERE ((rowv * rowv) / (rowvErr * rowvErr) +
(colv * colv) / (colvErr * colvErr) > 4)
-- where the velocities are reliable
</textarea><textarea style="display:none" id="q_1165868693">-- Using the BETWEEN syntax.
-- Find galaxies with an isophotal surface brightness (SB) larger
-- than 24 in the red band, and with an ellipticity > 0.5, and with the major
-- axis of the ellipse having a declination between 30" and 60" arc seconds.
-- This is also a simple query that uses a WHERE clause with three conditions
-- that must be met. We introduce the syntax 'BETWEEN' to do a range search.
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT TOP 100 ObjID
FROM Galaxy
WHERE r < 24 - rho
-- surface brightness brighter than 24 mag. per sq. arcsec in the red
-- Note that isolating r (indexed) on one side helps this run faster
and isoA_r between 30 and 60
-- major axis between 30" and 60"
and (power(q_r,2) + power(u_r,2)) > 0.25
-- square of ellipticity is > 0.5 squared. The SQL term 'power' is used for exponentiation.</textarea><textarea style="display:none" id="q_1514903499">-- Moving objects consistent with an asteroid.
-- Also a simple query, but we introduce the 'as' syntax, which allows us to
-- name derived quantities in the result file.
--
--This Sample Query will not work for SDSS3 contexts
SELECT TOP 10
objID,
sqrt( power(rowv,2) + power(colv, 2) ) as velocity
FROM PhotoObj
WHERE
(power(rowv,2) + power(colv, 2)) between 50 and 1000
</textarea><textarea style="display:none" id="q_214576614">-- Find quasars in imaging data.
-- as specified by Xiaohui Fan et.al.
-- A rather straightforward query, just with many conditions.
SELECT TOP 1000 run,
camCol,
rerun,
field,
objID,
u, g, r, i, z,
ra, dec
FROM Star -- or Galaxy
WHERE ( u - g > 2.0 or u > 22.3 )
and ( i < 19 )
and ( i > 0 )
and ( g - r > 1.0 )
and ( r - i <
(0.08 + 0.42 * (g - r - 0.96) )
or g - r > 2.26 )
and ( i - z < 0.25 )
</textarea><textarea style="display:none" id="q_619033119">-- Using object counting and logic in a query.
-- Find all objects similar to the colors of a quasar at 5.5<redshift<6.5.
SELECT count(*) as 'total',
sum( case when (Type=3) then 1 else 0 end) as 'Galaxies',
sum( case when (Type=6) then 1 else 0 end) as 'Stars',
sum( case when (Type not in (3,6)) then 1 else 0 end) as 'Other'
FROM PhotoPrimary -- for each object
WHERE (( u - g > 2.0) or (u > 22.3) ) -- apply the quasar color cut.
and ( i between 0 and 19 )
and ( g - r > 1.0 )
and ( (r - i < 0.08 + 0.42 * (g - r - 0.96)) or (g - r > 2.26 ) )
and ( i - z < 0.25 )
</textarea><textarea style="display:none" id="q_1653404421">-- Find galaxies that are blended with a star.
-- Output the deblended galaxy magnitudes.
-- This query introduces the use of multiple tables or views. You can assign
-- nicknames to tables as in the FROM clause below. Since you are using
-- multiple tables, you ,ust specify which table each quantity in the SELECT
-- clause comes from. Finally, the last line in the query is the join between
-- the two tables, which is achieved by requiring that a quantity present in
-- both tables be equal.
-- NOTE: This query times out (takes too long) without the "TOP 1000".
SELECT top 1000 G.ObjID, G.u, G.g, G.r, G.i, G.z --get the ObjID and final mags
FROM Galaxy G, Star S -- use two Views, Galaxy and Star, as a convenient mechanism to compare objects
WHERE G.parentID > 0 -- galaxy has a "parent", which tells us this object was deblended
and G.parentID = S.parentID -- and the star has the same parent
</textarea><textarea style="display:none" id="q_1527039772">-- Stars selected using Field criteria.
-- Give me the PSF colors of all stars brighter than g=20 that have PSP_STATUS = 2.
-- Another simple multi-table query.
SELECT TOP 1000
s.psfMag_g, -- or whatever you want from each object
s.run,
s.camCol,
s.rerun,
s.field
FROM Star s, Field f
WHERE s.fieldID = f.fieldID
and s.psfMag_g < 20
and f.pspStatus = 2</textarea><textarea style="display:none" id="q_1055015502">-- Objects selected by cuts on three tables.
-- Find the parameters for all objects in a selected field with
-- desired PSF width and range of columns.
-- Now we are using three tables, but it is still a simple query.
-- NOTE: This query times out (takes too long) without the "TOP 1000".
SELECT TOP 1000
f.run,
f.rerun,
f.camCol,
f.field,
p.objID,
p.ra,
p.dec,
p.Rowc,
p.Colc,
p.u,
p.modelMagErr_u ,
p.g,
p.modelMagErr_g,
p.r,
p.modelMagErr_r,
p.petroMag_r - p.extinction_r,
p.petroMagErr_r,
p.i,
p.modelMagErr_i,
p.z,
f.psfWidth_r
FROM
photoObj p, field f
WHERE
f.fieldid = p.fieldid
and f.psfWidth_r > 1.2
and p.colc > 400.0
</textarea><textarea style="display:none" id="q_1131150381">-- Find all objects within 30 arcseconds of one another
-- that have very similar colors: that is where the color ratios
-- u-g, g-r, r-I are less than 0.05m.
SELECT TOP 10 P.ObjID -- distinct cases
FROM PhotoPrimary P, -- P is the primary object
Neighbors N, -- N is the neighbor link
PhotoPrimary L -- L is the lens candidate of P
WHERE P.ObjID = N.ObjID -- N is a neighbor record
and L.ObjID = N.NeighborObjID -- L is a neighbor of P
and P.ObjID < L. ObjID -- avoid duplicates
and abs((P.u-P.g)-(L.u-L.g))<0.05 -- L and P have similar spectra.
and abs((P.g-P.r)-(L.g-L.r))<0.05
and abs((P.r-P.i)-(L.r-L.i))<0.05
and abs((P.i-P.z)-(L.i-L.z))<0.05
</textarea><textarea style="display:none" id="q_859289958">-- Find specific types of quasars using spectroscopy.
-- The easiest way to find quasars is by finding objects whose spectra have
-- been classified as quasars. This sample query searches the SpecObj
-- table for the IDs and redshifts of objects with the class column equal to 'QSO'
SELECT TOP 100 specObjID, z
FROM SpecObj
WHERE class = 'QSO' AND zWarning = 0
</textarea><textarea style="display:none" id="q_1033172010">-- Checking for errors using flags.
-- Another useful query is to see if the errors on moving (or
-- apparently moving) objects are correct. For example, it used to be that
-- some known QSOs were being flagged as moving objects. One way to look for
-- such objects is to compare the velocity to the error in velocity and see if
-- the "OBJECT1_MOVED" or "OBJECT2_BAD_MOVING_FIT" is set.
-- This query introduces bitwise logic for flags, and uses the 'as' syntax to
-- make the query more readable. Note that if a flag is not set, the value
-- will be zero. If you want to ensure multiple flags are not set, you can
-- either check that each individually is zero, or their sum is zero.
-- (From Gordon Richards)
SELECT TOP 1000
run,
rerun,
camcol,
field,
objID,
ra, dec,
rowv, colv,
rowvErr, colvErr,
i,
(flags & dbo.fPhotoFlags('MOVED')) as MOVED,
(flags & dbo.fPhotoFlags('BAD_MOVING_FIT')) as BAD_MOVING_FIT
FROM Galaxy
WHERE
(flags & (dbo.fPhotoFlags('MOVED') + dbo.fPhotoFlags('BAD_MOVING_FIT'))) > 0
and (rowv * rowv + colv * colv) >=
(rowvErr * rowvErr + colvErr * colvErr)</textarea><textarea style="display:none" id="q_976449187">-- Elliptical galaxies based on model fits.
-- Find all galaxies with a deVaucouleours profile and the
-- photometric colors consistent with an elliptical galaxy. NOTE THAT THE
-- NAMES and VALUES OF THE LIKELIHOODS HAVE CHANGED SINCE THE EDR; they are
-- now log likelihoods, and named accordingly (lDev is now lnlDev, etc.) to
-- indicate these are log likelihoods. This query has many conditions, and
-- also has the use of bitwise logic necessary for dealing with flags.
SELECT TOP 100 ObjID
FROM Galaxy as G
WHERE
G.lnlDev_r > G.lnlExp_r + 0.1
-- the likelihood of the deVaucouleours profile fit is 10% greater than the likelihood of the exponential fit
and G.lnlExp_r > -999
-- and the likelihoods are actually meaningful
and (G.flags & (dbo.fPhotoFlags('BINNED1') + dbo.fPhotoFlags('BINNED2') + dbo.fPhotoFlags('BINNED4'))) > 0
--and it is detected from at least one of the binned images ???
and (G.flags & ( dbo.fPhotoFlags('BLENDED') + dbo.fPhotoFlags('NODEBLEND') + dbo.fPhotoFlags('CHILD'))) != dbo.fPhotoFlags('BLENDED')
--and, if it is blended, it is either a child or not deblended further ??
and (G.flags & (dbo.fPhotoFlags('EDGE') + dbo.fPhotoFlags('SATURATED'))) = 0
-- and it is not near a ccd edge or saturated, where measurements may be bad
and G.petroMag_i > 17.5
-- and it is fainter than 17.5 in i-band
and (G.petroMag_r > 15.5 or G.petror50_r > 2)
and (G.petroMag_r > 0 and G.g > 0 and G.r > 0 and G.i > 0)
and ( (G.petroMag_r - G.extinction_r) < 19.2
and (G.petroMag_r - G.extinction_r <
(13.1 + (7/3)*(G.g - G.r) + 4 *(G.r - G.i) - 4 * 0.18 ) )
and ( (G.r - G.i - (G.g - G.r)/4 - 0.18) < 0.2 )
and ( (G.r - G.i - (G.g - G.r)/4 - 0.18) > -0.2 ) )
or ( (G.petroMag_r - G.extinction_r < 19.5)
and ( (G.r - G.i - (G.g - G.r)/4 - 0.18) >
(0.45 - 4*(G.g - G.r) ) )
and ( (G.g - G.r) > (1.35 + 0.25 *(G.r - G.i) ) ) )
-- and many constraints on colors and mags are met to make it have
-- elliptical-type colors.
</textarea><textarea style="display:none" id="q_1404790795">-- Galaxies with bluer centers.
-- by Michael Strauss. For all galaxies
-- with r_Petro < 18, not saturated, not bright, and not edge, give me those
-- with centers appreciably bluer than their outer parts, i.e., define the
-- center color as: u_psf - g_psf and define the outer color as: u_model -
-- g_model; give me all objs which have (u_model - g_model) - (u_psf - g_psf)
-- < -0.4
-- Another flags-based query.
SELECT TOP 1000
colc_u, colc_g, objID
FROM Galaxy
WHERE
( Flags & (dbo.fPhotoFlags('SATURATED') +
dbo.fPhotoFlags('BRIGHT') +
dbo.fPhotoFlags('EDGE')) ) = 0
and petrorad_r < 18
and ((colc_u - colc_g) - (psfMag_u - psfMag_g)) < -0.4</textarea><textarea style="display:none" id="q_1368831015">-- Diameter-limited sample of galaxies
-- from James Annis.
SELECT TOP 1000
run,
camCol,
rerun,
field,
objID,
ra,
dec
FROM Galaxy
WHERE ( flags & (dbo.fPhotoFlags('BINNED1')
+ dbo.fPhotoFlags('BINNED2')
+ dbo.fPhotoFlags('BINNED4')) ) > 0
and ( flags & (dbo.fPhotoFlags('BLENDED')
+ dbo.fPhotoFlags('NODEBLEND')
+ dbo.fPhotoFlags('CHILD')) ) != dbo.fPhotoFlags('BLENDED')
and ( ( (flags & dbo.fPhotoFlags('NOPETRO') = 0)
and petrorad_i > 15)
or ( (flags & dbo.fPhotoFlags('NOPETRO') > 0)
and petrorad_i > 7.5)
or ( (flags & dbo.fPhotoFlags('TOO_LARGE') > 0)
and petrorad_i > 2.5)
or
( (flags & dbo.fPhotoFlags('SATURATED') = 0)
and petrorad_i > 17.5) )
</textarea><textarea style="display:none" id="q_642208693">-- Extremely red galaxies.
-- from James Annis.
-- Similar to the diameter limited sample query.
SELECT TOP 1000
g.run,
g.camCol,
g.rerun,
g.field,
g.objID,
g.ra, g.dec
FROM Field f, Galaxy g
WHERE
g.fieldID = f.fieldID
and ( g.flags & (dbo.fPhotoFlags('BINNED1')
+ dbo.fPhotoFlags('BINNED2')
+ dbo.fPhotoFlags('BINNED4')) ) > 0
and ( g.flags & (dbo.fPhotoFlags('BLENDED')
+ dbo.fPhotoFlags('NODEBLEND')
+ dbo.fPhotoFlags('CHILD')) ) != dbo.fPhotoFlags('BLENDED')
and ( g.flags & (dbo.fPhotoFlags('COSMIC_RAY')
+ dbo.fPhotoFlags('INTERP')) ) = 0
and f.psfWidth_r < 1.5
and (g.i - g.z > 1.0 ) -- i and z in primary tables DO NOT include extinction</textarea><textarea style="display:none" id="q_674238270">-- A version of the LRG sample.
-- by James Annis.
-- Another query with many conditions and flag tests.
SELECT TOP 100
run,
camCol,
rerun,
field,
objID,
ra,
dec
FROM Galaxy
WHERE ( ( flags & (dbo.fPhotoFlags('BINNED1')
+ dbo.fPhotoFlags('BINNED2')
+ dbo.fPhotoFlags('BINNED4')) ) > 0
and ( flags & (dbo.fPhotoFlags('BLENDED')
+ dbo.fPhotoFlags('NODEBLEND')
+ dbo.fPhotoFlags('CHILD')) ) != dbo.fPhotoFlags('BLENDED')
and ( flags & (dbo.fPhotoFlags('EDGE')
+ dbo.fPhotoFlags('SATURATED')) ) = 0
and petroMag_i > 17.5
and (petroMag_r > 15.5 or petror50_r > 2)
and (petroMag_r > 0 and g > 0 and r > 0 and i > 0)
and ( (petroMag_r-extinction_r) < 19.2
and (petroMag_r - extinction_r <
(13.1 + (7/3) * (dered_g - dered_r) + 4 * (dered_r - dered_i) - 4 * 0.18) )
and ( (dered_r - dered_i - (dered_g - dered_r)/4 - 0.18) < 0.2)
and ( (dered_r - dered_i - (dered_g - dered_r)/4 - 0.18) > -0.2)
--dered_ quantities already include extinction
and ( (petroMag_r - extinction_r +
2.5 * LOG10(2 * 3.1415 * petror50_r * petror50_r)) < 24.2) )
or ( (petroMag_r - extinction_r < 19.5)
and ( (dered_r - dered_i - (dered_g - dered_r)/4 - 0.18) > (0.45 - 4 * (dered_g - dered_r)) )
and ( (dered_g - dered_r) > (1.35 + 0.25 * (dered_r - dered_i)) ) )
and ( (petroMag_r - extinction_r +
2.5 * LOG10(2 * 3.1415 * petror50_r * petror50_r) ) < 23.3 ) )</textarea><textarea style="display:none" id="q_1020817074">-- Find galaxies with specific spectra.
-- Namely, they have an equivalent width in
-- H_alpha > 40 Angstroms. We want object ID's from the photometry (Galaxy)
-- but constraints from spectroscopy. The line widths and IDs are stored in
-- SpecLine. --This is a simple query, but now we are using three tables. The
-- spectroscopy tables of measured lines are arranged non-intuitively, and we
-- urge users to read about them on the DAS help pages. --IMPORTANT NOTE:
-- Each spectroscopic object now has a match to at least two photometric
-- objects, one in Target and one in Best. Therefore, when performing a join
-- between spectroscopic photometric objects, you must specify either
-- PhotoObj.ObjID=SpecObj.bestObjID or PhotoObj.ObjID = SpecObj.targetObjID.
-- Normally, the default photometric database is BEST, so you will want to use
-- SpecObj.bestObjID
--
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT G.ObjID -- we want the photometric ObjID
FROM Galaxy as G, -- G is the galaxy
SpecObj as S, -- S is the spectra of galaxy G
SpecLine as L, -- L is a line of S
SpecLineNames as LN -- the names of the lines
WHERE G.ObjID = S.bestObjID -- connect the galaxy to the spectrum
and S.SpecObjID = L.SpecObjID -- and the spectral line L is detected in the spectrum
and L.LineId = LN.value -- L is the H alpha line
and LN.name = 'Ha_6565'
and L.ew > 40 -- and H alpha is at least 40 angstroms wide.
</textarea><textarea style="display:none" id="q_1695980969">-- Find galaxies with more specific spectra.
-- Same as prior query, but also require weak Hbeta line (Halpha/Hbeta > 20.)
--
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT G.ObjID -- return qualifying galaxies
FROM Galaxy as G, -- G is the galaxy
SpecObj as S, -- S is the spectra of galaxy G
SpecLine as L1, -- L1 is a line of S
SpecLine as L2, -- L2 is a second line of S
specLineNames as LN1, -- the names of the lines (Halpha)
specLineNames as LN2 -- the names of the lines (Hbeta)
WHERE G.ObjID = S.BestObjID -- connect the galaxy to the spectrum
and S.SpecObjID = L1.SpecObjID -- L1 is a line of S.
and S.SpecObjID = L2.SpecObjID -- L2 is a line of S.
and L1.LineId = LN1. value
and LN1.name = 'Ha_6565' -- L1 is the H alpha line
and L2.LineId = LN2.value -- L2 is the H alpha line
and LN2.name = 'Hb_4863' --
and L1.ew > 200 -- BIG Halpha
and L2.ew > 10 -- significant Hbeta emission line
and L2.ew * 20 < L1.ew -- Hbeta is comparatively small
</textarea><textarea style="display:none" id="q_1794028875">-- Find binary stars with specific colors.
-- At least one of them should have the colors of a white dwarf.
SELECT TOP 100 s1.objID as s1, s2.objID as s2
FROM Star S1, -- S1 is the white dwarf
Neighbors N, -- N is the precomputed neighbors links
Star S2 -- S2 is the second star
WHERE S1.objID = N. objID -- S1 and S2 are neighbors-within 30 arc sec
and S2.objID = N.NeighborObjID
and N.neighborType = dbo.fPhotoType('Star') -- and S2 is a star
and N.distance < .05 -- the 3 arcsecond test
and ((S1.u - S1.g) < 0.4 ) -- and S1 meets Paul Szkodys color cut for
and (S1.g - S1.r) < 0.7 -- white dwarfs.
and (S1.r - S1.i) > 0.4
and (S1.i - S1.z) > 0.4
</textarea><textarea style="display:none" id="q_875447540">-- Find quasars with a broad absorption line and a nearby galaxy.
-- within 10 arcseconds.
-- Return both the quasars and the galaxies.
--
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT Q.BestObjID as Quasar_candidate_ID , G.ObjID as Galaxy_ID, N.distance
FROM SpecObj as Q, -- Q is the specObj of the quasar candidate
Neighbors as N, -- N is the Neighbors list of Q
Galaxy as G, -- G is the nearby galaxy
SpecClass as SC, -- Spec Class
SpecLine as L, -- L is the broad line we are looking for
SpecLineNames as LN -- Line Name
WHERE Q.SpecClass =SC.value -- Q is a QSO
and SC.name in ('QSO', 'HIZ_QSO') -- Spectrum says "QSO"
and Q.SpecObjID = L.SpecObjID -- L is a spectral line of Q.
and L.LineID = LN.value -- line found and
and LN.Name != 'UNKNOWN' -- not not identified
and L.ew < -10 -- but its a prominent absorption line
and Q.BestObjID = N.ObjID -- N is a neighbor record
and G.ObjID = N.NeighborObjID -- G is a neighbor of Q
and N.distance < 10.0/60 -- and it is within 10 arcseconds of the Q.
</textarea><textarea style="display:none" id="q_408046859">-- Find galaxies without saturated pixels within 1' of a given point.
-- ra=185.0, dec=-0.5. This query uses a function fGetNearbyObjEq,
-- which takes 3 arguments (ra,dec, distance in arcmin); this function uses
-- the Neighbors table. The Neighbors table and the Galaxy table have in
-- common the objID, so we have to select objects from both where the objIDs
-- are the same. The output of the function is a table with the Galaxy Object
-- ID and distance in arcmin from the input. This query introduces the use of
-- a JOIN to combine table contents. Also, we use the 'orDER BY' syntax,
-- which will sort the output.
SELECT TOP 100 G.objID, GN.distance
FROM Galaxy as G
JOIN dbo.fGetNearbyObjEq(185.,-0.5, 1) as GN -- this function outputs a table, so we have to do a join
on G.objID = GN.objID -- get objects from temporary neighbors table GN with desired ObjID
WHERE (G.flags & dbo.fPhotoFlags('saturated')) = 0 -- and the object is not saturated. f.PhotoFlags is a function that interprets the flag bits.
ORDER BY distance -- sort these by distance
</textarea><textarea style="display:none" id="q_2023911456">-- Ellipticals with odd lines.
-- Find all elliptical galaxies with spectra that have an anomalous
-- emission line. This query introduces the SQL syntax DISTINCT, which will
-- return only one instance of the requested parameter (ObjID, in this case),
-- because our query may return the same object more than once. This is also
-- the first nested query, where we use one SELECT (the inner one) to get a
-- group of objects we are not interested in. The outer SELECT includes the
-- new syntax 'not in', which is used to perform the exclusion.
--
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT DISTINCT G.ObjID -- return qualifying galaxies
FROM
Galaxy as G, -- G is the galaxy
SpecObjAll as S, -- S is the spectra of galaxy G
SpecLineAll as L, -- L is a line of S
-- we must use SpecLineAll because SpecLine only has ID's lines
XCRedshift as XC -- the template cross-correlation redshift
WHERE G.ObjID = S.bestObjID -- connect galaxy to the spectrum
and S.SpecObjID = L.SpecObjID -- The line L must be in the spectrum S
and S.SpecObjID = XC.SpecObjID -- and there is a crosscorrelation redshift
and XC.tempNo = 8 -- Template('Elliptical') -- best Cross correlation template used is "elliptical"
and L.LineID = 0
and L.ew > 10 -- and the line is prominent by some definition, in this case, the equivalent width is over 10 Angstroms
and S.SpecObjID not in (
-- insist that there are no other lines
SELECT S.SpecObjID -- This is the chosen line.
FROM SpecLine as L1 -- L1 is another line...
-- by using SpecLine, we are automatically requiring that the line
-- be identified
WHERE S.SpecObjID = L1.SpecObjID -- ...for this object...
and abs(L.wave - L1.wave) <.01
-- ...at nearly the same wavelength...
)
</textarea><textarea style="display:none" id="q_1739829469">-- Search near BCG galaxies.
-- For each galaxy in the BCG data set (brightest cluster galaxy),
-- in 160<right ascension<170, -25<declination<35 count the number of
-- galaxies within 30" of it that have a photoz within 0.05
-- of that galaxy.
-- An extremely complex WHERE clause.
SELECT G.objID, count(N.NeighborObjID) as pop
FROM Galaxy as G, -- first gravitational lens candidate
Neighbors as N, -- precomputed list of neighbors
Galaxy as U, -- a neighbor galaxy of G
photoZ as Gpz, -- photoZ of G.
photoZ as Npz -- Neighbor photoZ
WHERE G.ra between 160 and 170
and G.dec between -5 and 5
and G.objID = N.objID -- connect G and U via the neighbors table
and U.objID = N.neighborObjID -- so that we know G and U are within
and N.objID < N.neighborObjID -- 30 arcseconds of one another.
and G.objID = Gpz.objID
and U.objID = Npz.objID
and abs(Gpz.Z - Npz.Z) < 0.05 -- restrict the photoZ differences
and (G.flags & (dbo.fPhotoFlags('BINNED1') + dbo.fPhotoFlags('BINNED2') + dbo.fPhotoFlags('BINNED4'))) > 0
--and it is detected from at least one of the binned images
and (G.flags & ( dbo.fPhotoFlags('BLENDED') + dbo.fPhotoFlags('NODEBLEND') + dbo.fPhotoFlags('CHILD'))) != dbo.fPhotoFlags('BLENDED')
--and, if it is blended, it is either a child or not deblended further ??
and (G.flags & (dbo.fPhotoFlags('EDGE') + dbo.fPhotoFlags('SATURATED'))) = 0
-- and it is not near a ccd edge or saturated, where measurements may be bad
-- and apply color cut for a BCG courtesy of James Annis of Fermilab
and G.petroMag_i > 17.5
and (G.petroMag_r > 15.5 or G.petror50_r > 2)
and (G.petroMag_r < 30 and G.g < 30 and G.r < 30 and G.i < 30)
and (G.r < 19.2
and ( 1=1 or -- huh?
(G.r < (13.1 + (7/3)*(G.g - G.r) +
-- deRed_r < 13.1 + 0.7 / 0.3 * deRed_gr
4 *(G.r - G.i - 0.18 ))
-- 1.2 / 0.3 * deRed_ri
and (( G.r - G.i - (G.g - G.r)/4 - 0.18) BETWEEN -0.2 and 0.2 )
and ((G.r +
-- petSB - deRed_r + 2.5 log10(2Pi*petror50^2)
2.5 * LOG( 2 * 3.1415 * G.petror50_r * G.petror50_r )) < 24.2 )
)
or
( (G.r < 19.5 )
and (( G.r - G.i -(G.g - G.r)/4 -.18) >
-- - deRed_gr/4 - 0.18
-- cperp = deRed_ri
(0.45 - 4*( G.g - G.r)))
-- 0.45 - deRed_gr/0.25
and ((G.g - G.r) > ( 1.35 + 0.25 *(G.r - G.i)))
and ((G.r +
-- petSB - deRed_r + 2.5 log10(2Pi*petror50^2)
2.5 * LOG( 2 * 3.1415 * G.petror50_r * G.petror50_r )) < 23.3 )
)) )
group by G.objID
</textarea><textarea style="display:none" id="q_1716646730">-- Broadest line of each spectrum with its ID.
-- (or more generally, all the columns for
-- the spectral line with the highest/lowest something)? The line width is
-- stored in the column sigma, the identification is in the column restwave.
-- (Sebastian Jester )
--
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT
L.specObjId,
L.specLineID,
sMax.Maxwidth -- get the spectroscopic object ID, the line ID, and the width
FROM specLine L,
(SELECT specObjID,
Max(waveMax-waveMin) as MaxWidth
-- Define MaxWidth as the largest difference in the min and max wavelength of
-- an identified line, using the built-in Max function of SQL
FROM SpecLine
GROUP BY specObjID) as sMax
-- sMax contains a single specObjID and MaxWidth. Remember that for each line
-- identified in a given object's spectrum, there is an entry in
-- SpecLine. This means that each specObjID appears many times in SpecLine,
-- once for each line found, and they must be aggregated before performing any
-- operation such as Max. The GROUP BY is thus NECESSARY.
-- The upper FROM clause is telling us we will use the table SpecLine and this
-- new output called sMax, which contains one entry with the SpecObjID and
-- MaxWidth. If we used some other function instead of 'Max', such as 'top
-- 10', sMax would have more than row.
WHERE
L.specObjID = sMax.specObjID
and (L.waveMax-L.waveMin) = sMax.MaxWidth
-- Just as with the specObjID, each specLineID appears many times in specLine.
-- This final WHERE clause makes sure we get the one specLineID from SpecObj
-- which matches the unique combination of specObjID and MaxWidth in sMax.
</textarea><textarea style="display:none" id="q_856840643">-- Gridded galaxy counts and masks. Actually consists of TWO queries:
-- 1) Create a gridded count of galaxies with u-g > 1 and r < 21.5 over -1 < dec < 1,
-- and 179 < R.A. < 181, on a grid, and create a map of masks over the same grid.
-- Scan the table for galaxies and group them in cells 2 arc-minuteson a side. Provide
-- predicates for the color restrictions on u-g and r and to limit the search to the
-- portion of the sky defined by the right ascension and declination conditions. Return
-- the count of qualifying galaxies in each cell.
-- 2) Run another query with the same grouping, but with a predicate to include only
-- objects such as satellites, planets, and airplanes that obscure the cell. The second
-- query returns a list of cell coordinates that serve as a mask for the first query.
--- First find the gridded galaxy count (with the color cut)
--- In local tangent plane, ra/cos(dec) is a linear degree.
SELECT cast((ra/cos(cast(dec*30 as int)/30.0))*30 as int)/30.0 as raCosDec,
cast(dec*30 as int)/30.0 as dec,
count(*) as pop
FROM Galaxy as G
JOIN dbo.fHTMCoverRegion('CHULL J2000 179 -1 179 1 181 1 181 -1') AS T
ON G.htmID BETWEEN T.HTMIDstart AND T. HTMIDend
WHERE ra between 179 and 181
and dec between -1 and 1
and u-g > 1
and r < 21.5
GROUP BY cast((ra/cos(cast(dec*30 as int)/30.0))*30 as int)/30.0,
cast(dec*30 as int)/30.0
-- now build mask grid.
-- This is a separate query if no temp tables can be made
SELECT cast((ra/cos(cast(dec*30 as int)/30.0))*30 as int)/30.0 as raCosDec,
cast(dec*30 as int)/30.0 as dec,
count(*) as pop
FROM PhotoObj as PO
JOIN dbo.fHTMCoverRegion('CHULL J2000 179 -1 179 1 181 1 181 -1') AS T
ON PO.htmID BETWEEN T.HTMIDstart AND T.HTMIDend
JOIN PhotoType as PT ON PO.type = PT.value
WHERE
ra between 179 and 181
and dec between -1 and 1
and PT.name in ('COSMIC_RAY', 'DEFECT', 'GHOST', 'TRAIL', 'UNKNOWN')
GROUP BY cast((ra/cos(cast(dec*30 as int)/30.0))*30 as int)/30.0,
cast(dec*30 as int)/30.0 </textarea><textarea style="display:none" id="q_211714083">-- Create a count of galaxies for each of the HTM triangles.
-- Galaxies should satisfy a certain color cut,
-- like 0.7u-0.5g-0.2i<1.25 && r<21.75, output it in a form
-- adequate for visualization.
SELECT (htmID / power(2,24)) as htm_8 ,
-- group by 8-deep HTMID (rshift HTM by 12)
avg(ra) as ra,
avg(dec) as [dec],
count(*) as pop -- return center point and count for display
FROM Galaxy -- only look at galaxies
WHERE (0.7*u - 0.5*g - 0.2*i) < 1.25 -- meeting this color cut
and r < 21.75 -- brighter than 21.75 magnitude in red band.
group by (htmID /power(2,24)) -- group into 8-deep HTM buckets.
</textarea><textarea style="display:none" id="q_137356135">-- Find stars with multiple measurements with magnitude variations >0.1.
-- Note that this runs very slowly unless explicit workarounds are included
-- for some SQLServer Optimizer bugs, which are NOT included here
SELECT TOP 100
S1.objID as objID1, S2.objID as ObjID2 -- select object IDs of star and its pair
FROM Star as S1, -- the primary star
photoObj as S2, -- the second observation of the star
neighbors as N -- the neighbor record
WHERE S1.objID = N.objID -- insist the stars are neighbors
and S2.objID = N.neighborObjID -- using precomputed neighbors table
and distance < 0.5/60 -- distance is 0.5 arc second or less
and S1.run != S2.run -- observations are two different runs
and S2.type = dbo.fPhotoType('Star') -- S2 is indeed a star
and S1.u between 1 and 27 -- S1 magnitudes are reasonable
and S1.g between 1 and 27
and S1.r between 1 and 27
and S1.i between 1 and 27
and S1.z between 1 and 27
and S2.u between 1 and 27 -- S2 magnitudes are reasonable.
and S2.g between 1 and 27
and S2.r between 1 and 27
and S2.i between 1 and 27
and S2.z between 1 and 27
and ( -- and one of the colors is different.
abs(S1.u-S2.u) > .1 + (abs(S1.Err_u) + abs(S2.Err_u))
or abs(S1.g-S2.g) > .1 + (abs(S1.Err_g) + abs(S2.Err_g))
or abs(S1.r-S2.r) > .1 + (abs(S1.Err_r) + abs(S2.Err_r))
or abs(S1.i-S2.i) > .1 + (abs(S1.Err_i) + abs(S2.Err_i))
or abs(S1.z-S2.z) > .1 + (abs(S1.Err_z) + abs(S2.Err_z))
)
</textarea><textarea style="display:none" id="q_1480779043">-- This query uses the new SQL Server 2005 CROSS APPLY and OUTER APPLY
-- constructs to apply a table-valued function to the results of a query.
-- In this example, we use the fFootPrintEq function which returns a list
-- of SDSS regions that intersect the area specified by the RA, dec and
-- radius, or NULL if the area is outside the SDSS footprint.
-- For each point in the input list, in this case the result of a query
-- on PhotoObj, return "yes" or "no" depending on whether the point is in
-- the SDSS footprint or not, and any other needed columns.
SELECT top 100 objID, ra, dec,
(case when p.type is null then 'NO' else 'YES' end) as found
FROM PhotoObj AS p
OUTER APPLY dbo.fFootprintEq(ra,dec,0.1)
WHERE (ra between 179.5 and 182.3) and (dec between -1.0 and 1.8)
</textarea>
<textarea style="display:none" id="q_1195248688">-- Basic_SELECT_FROM_WHERE
-- Find objects in a particular field.
SELECT objID,
field, ra, dec -- Get the unique object ID, field number, and coords
FROM PhotoObj -- From the photometric data
WHERE fieldID = 587722951961673728 -- that is in a specific field
</textarea><textarea style="display:none" id="q_1747257364">-- Galaxies meeting two simple criteria.
-- Find all galaxies brighter than r magnitude 17, where the local
-- extinction is > 0.275. This is a simple query that uses a WHERE clause,
-- but now two conditions that must be met simultaneously.
--
-- Finds 6604 galaxies in under 10 mins on DR2, but beware that increasing
-- the limiting r magnitude will significantly add to the execution time.
SELECT objID
FROM Galaxy
WHERE
r < 17 -- r IS NOT deredenned
and extinction_r > 0.275 -- extinction more than 0.175
</textarea><textarea style="display:none" id="q_1374627809">-- Find all objects with unclassified spectra.
-- A simple SELECT-FROM-WHERE query, using a function
--
-- On DR2, returns 3109 rows in 20 sec.
SELECT specObjID
FROM SpecObj
WHERE SpecClass = dbo.fSpecClass('UNKNOWN')</textarea><textarea style="display:none" id="q_1381525768">-- Galaxies meeting multiple simple criteria.
-- Find all galaxies with blue surface brightness between 23 and 25
-- mag per square arcseconds, and -10 < supergalactic latitude (sgb) < 10, and
-- declination less than zero. Currently, we have to live with ra/dec until we
-- get galactic coordinates. To calculate surface brightness per sq. arcsec,
-- we use (g + rho), where g is the blue magnitude, and rho= 5*log(r). This
-- query now has three requirements, one involving simple math.
--
-- On DR2, returns 61090 rows in 330 sec.
SELECT objID
FROM Galaxy
WHERE ra between 178 and 180
and dec < 0
-- and (g+rho) between 23 and 25
and g between (23-rho) and (25-rho)
-- g is the blue magnitude, and rho= 5*log(Petro radius)</textarea><textarea style="display:none" id="q_909071920">-- Using spatial unit vectors for coordinate cuts.
-- Find galaxies in a given area of the sky, using a coordinate cut
-- in the unit vector cx,cy,cz that corresponds to a specific RA range.
-- Another simple query that uses math in the WHERE clause.
--
-- Finds 100 galaxies in 230 sec on DR2, but this is a very slow way to do
-- coordinate cuts. Using RA/dec is *much* faster due to indexing.
--
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT TOP 100 colc_g, colc_r
FROM Galaxy
WHERE
(-0.466 * cx + 0.689 * cy>=0)
and (-0.385 * cx - 0.173 * cy <0)
</textarea><textarea style="display:none" id="q_1357802971">-- Find CVs using colors.
-- Search for Cataclysmic Variables and pre-CVs with White Dwarfs and
-- very late secondaries. Just uses some simple color cuts from Paula Szkody.
-- Another simple query that uses math in the WHERE clause
--
-- Finishes in 72 sec on DR2.
SELECT TOP 10000 run,
camCol,
rerun,
field,
objID,
u, g, r, i, z,
ra, dec -- Just get some basic quantities
FROM PhotoPrimary -- From all primary detections, regardless of class
WHERE u - g < 0.4
and g - r < 0.7
and r - i > 0.4
and i - z > 0.4 -- that meet the color criteria
</textarea><textarea style="display:none" id="q_1954141537">-- Getting a subsample of the data.
-- Uses the integer short object id (obj) and the '%' syntax (like awk)
-- to get every 1000th object. THIS IS NOT A TRULY RANDOM SUBSET!
--
-- Returns 11367 objects in DR2 (in about 10-15mins).
SELECT u, g, r, i, z
FROM Galaxy with (nolock)
WHERE (objID%1000) = 1
AND (r between 18 and 21)
</textarea><textarea style="display:none" id="q_545014296">-- Low-z QSO candidates using color cuts.
-- from Gordon Richards.
-- Also a simple query with a long WHERE clause.
SELECT TOP 1000 g, run, rerun, camcol, field, objID
FROM
Galaxy
WHERE (
(g <= 22) and
(u-g >= -0.27) and (u-g < 0.71) and
(g-r >= -0.24) and (g-r < 0.35) and
(r-i >= -0.27) and (r-i < 0.57) and
(i-z >= -0.35) and (i-z < 0.70)
)</textarea><textarea style="display:none" id="q_547865327">-- Get object velocities and errors.
-- This is also a simple query that uses a WHERE clause.
-- However, now we perform a more complex mathematical operation.
SELECT TOP 1000
run, -- get a bunch of quantities
camCol,
field,
objID,
rowC, colC, rowV, colV, rowVErr, colVErr,
flags,
psfMag_u, psfMag_g, psfMag_r, psfMag_i, psfMag_z,
psfMagErr_u, psfMagErr_g, psfMagErr_r, psfMagErr_i, psfMagErr_z
FROM PhotoPrimary
WHERE ((rowv * rowv) / (rowvErr * rowvErr) +
(colv * colv) / (colvErr * colvErr) > 4)
-- where the velocities are reliable
</textarea><textarea style="display:none" id="q_716142064">-- Using the BETWEEN syntax.
-- Find galaxies with an isophotal surface brightness (SB) larger
-- than 24 in the red band, and with an ellipticity > 0.5, and with the major
-- axis of the ellipse having a declination between 30" and 60" arc seconds.
-- This is also a simple query that uses a WHERE clause with three conditions
-- that must be met. We introduce the syntax 'BETWEEN' to do a range search.
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT TOP 100 ObjID
FROM Galaxy
WHERE r < 24 - rho
-- surface brightness brighter than 24 mag. per sq. arcsec in the red
-- Note that isolating r (indexed) on one side helps this run faster
and isoA_r between 30 and 60
-- major axis between 30" and 60"
and (power(q_r,2) + power(u_r,2)) > 0.25
-- square of ellipticity is > 0.5 squared. The SQL term 'power' is used for exponentiation.</textarea><textarea style="display:none" id="q_272200048">-- Moving objects consistent with an asteroid.
-- Also a simple query, but we introduce the 'as' syntax, which allows us to
-- name derived quantities in the result file.
--
--This Sample Query will not work for SDSS3 contexts
SELECT TOP 10
objID,
sqrt( power(rowv,2) + power(colv, 2) ) as velocity
FROM PhotoObj
WHERE
(power(rowv,2) + power(colv, 2)) between 50 and 1000
</textarea><textarea style="display:none" id="q_753648351">-- Find quasars in imaging data.
-- as specified by Xiaohui Fan et.al.
-- A rather straightforward query, just with many conditions.
SELECT TOP 1000 run,
camCol,
rerun,
field,
objID,
u, g, r, i, z,
ra, dec
FROM Star -- or Galaxy
WHERE ( u - g > 2.0 or u > 22.3 )
and ( i < 19 )
and ( i > 0 )
and ( g - r > 1.0 )
and ( r - i <
(0.08 + 0.42 * (g - r - 0.96) )
or g - r > 2.26 )
and ( i - z < 0.25 )
</textarea><textarea style="display:none" id="q_1150951472">-- Using object counting and logic in a query.
-- Find all objects similar to the colors of a quasar at 5.5<redshift<6.5.
SELECT count(*) as 'total',
sum( case when (Type=3) then 1 else 0 end) as 'Galaxies',
sum( case when (Type=6) then 1 else 0 end) as 'Stars',
sum( case when (Type not in (3,6)) then 1 else 0 end) as 'Other'
FROM PhotoPrimary -- for each object
WHERE (( u - g > 2.0) or (u > 22.3) ) -- apply the quasar color cut.
and ( i between 0 and 19 )
and ( g - r > 1.0 )
and ( (r - i < 0.08 + 0.42 * (g - r - 0.96)) or (g - r > 2.26 ) )
and ( i - z < 0.25 )
</textarea><textarea style="display:none" id="q_106085622">-- Find galaxies that are blended with a star.
-- Output the deblended galaxy magnitudes.
-- This query introduces the use of multiple tables or views. You can assign
-- nicknames to tables as in the FROM clause below. Since you are using
-- multiple tables, you ,ust specify which table each quantity in the SELECT
-- clause comes from. Finally, the last line in the query is the join between
-- the two tables, which is achieved by requiring that a quantity present in
-- both tables be equal.
-- NOTE: This query times out (takes too long) without the "TOP 1000".
SELECT top 1000 G.ObjID, G.u, G.g, G.r, G.i, G.z --get the ObjID and final mags
FROM Galaxy G, Star S -- use two Views, Galaxy and Star, as a convenient mechanism to compare objects
WHERE G.parentID > 0 -- galaxy has a "parent", which tells us this object was deblended
and G.parentID = S.parentID -- and the star has the same parent
</textarea><textarea style="display:none" id="q_1713017857">-- Stars selected using Field criteria.
-- Give me the PSF colors of all stars brighter than g=20 that have PSP_STATUS = 2.
-- Another simple multi-table query.
SELECT TOP 1000
s.psfMag_g, -- or whatever you want from each object
s.run,
s.camCol,
s.rerun,
s.field
FROM Star s, Field f
WHERE s.fieldID = f.fieldID
and s.psfMag_g < 20
and f.pspStatus = 2</textarea><textarea style="display:none" id="q_270075329">-- Objects selected by cuts on three tables.
-- Find the parameters for all objects in a selected field with
-- desired PSF width and range of columns.
-- Now we are using three tables, but it is still a simple query.
-- NOTE: This query times out (takes too long) without the "TOP 1000".
SELECT TOP 1000
f.run,
f.rerun,
f.camCol,
f.field,
p.objID,
p.ra,
p.dec,
p.Rowc,
p.Colc,
p.u,
p.modelMagErr_u ,
p.g,
p.modelMagErr_g,
p.r,
p.modelMagErr_r,
p.petroMag_r - p.extinction_r,
p.petroMagErr_r,
p.i,
p.modelMagErr_i,
p.z,
f.psfWidth_r
FROM
photoObj p, field f
WHERE
f.fieldid = p.fieldid
and f.psfWidth_r > 1.2
and p.colc > 400.0
</textarea><textarea style="display:none" id="q_1540370546">-- Find all objects within 30 arcseconds of one another
-- that have very similar colors: that is where the color ratios
-- u-g, g-r, r-I are less than 0.05m.
SELECT TOP 10 P.ObjID -- distinct cases
FROM PhotoPrimary P, -- P is the primary object
Neighbors N, -- N is the neighbor link
PhotoPrimary L -- L is the lens candidate of P
WHERE P.ObjID = N.ObjID -- N is a neighbor record
and L.ObjID = N.NeighborObjID -- L is a neighbor of P
and P.ObjID < L. ObjID -- avoid duplicates
and abs((P.u-P.g)-(L.u-L.g))<0.05 -- L and P have similar spectra.
and abs((P.g-P.r)-(L.g-L.r))<0.05
and abs((P.r-P.i)-(L.r-L.i))<0.05
and abs((P.i-P.z)-(L.i-L.z))<0.05
</textarea><textarea style="display:none" id="q_365239915">-- Find specific types of quasars using spectroscopy.
-- The easiest way to find quasars is by finding objects whose spectra have
-- been classified as quasars. This sample query searches the SpecObj
-- table for the IDs and redshifts of objects with the class column equal to 'QSO'
SELECT TOP 100 specObjID, z
FROM SpecObj
WHERE class = 'QSO' AND zWarning = 0
</textarea><textarea style="display:none" id="q_179278427">-- Checking for errors using flags.
-- Another useful query is to see if the errors on moving (or
-- apparently moving) objects are correct. For example, it used to be that
-- some known QSOs were being flagged as moving objects. One way to look for
-- such objects is to compare the velocity to the error in velocity and see if
-- the "OBJECT1_MOVED" or "OBJECT2_BAD_MOVING_FIT" is set.
-- This query introduces bitwise logic for flags, and uses the 'as' syntax to
-- make the query more readable. Note that if a flag is not set, the value
-- will be zero. If you want to ensure multiple flags are not set, you can
-- either check that each individually is zero, or their sum is zero.
-- (From Gordon Richards)
SELECT TOP 1000
run,
rerun,
camcol,
field,
objID,
ra, dec,
rowv, colv,
rowvErr, colvErr,
i,
(flags & dbo.fPhotoFlags('MOVED')) as MOVED,
(flags & dbo.fPhotoFlags('BAD_MOVING_FIT')) as BAD_MOVING_FIT
FROM Galaxy
WHERE
(flags & (dbo.fPhotoFlags('MOVED') + dbo.fPhotoFlags('BAD_MOVING_FIT'))) > 0
and (rowv * rowv + colv * colv) >=
(rowvErr * rowvErr + colvErr * colvErr)</textarea><textarea style="display:none" id="q_2005973150">-- Elliptical galaxies based on model fits.
-- Find all galaxies with a deVaucouleours profile and the
-- photometric colors consistent with an elliptical galaxy. NOTE THAT THE
-- NAMES and VALUES OF THE LIKELIHOODS HAVE CHANGED SINCE THE EDR; they are
-- now log likelihoods, and named accordingly (lDev is now lnlDev, etc.) to
-- indicate these are log likelihoods. This query has many conditions, and
-- also has the use of bitwise logic necessary for dealing with flags.
SELECT TOP 100 ObjID
FROM Galaxy as G
WHERE
G.lnlDev_r > G.lnlExp_r + 0.1
-- the likelihood of the deVaucouleours profile fit is 10% greater than the likelihood of the exponential fit
and G.lnlExp_r > -999
-- and the likelihoods are actually meaningful
and (G.flags & (dbo.fPhotoFlags('BINNED1') + dbo.fPhotoFlags('BINNED2') + dbo.fPhotoFlags('BINNED4'))) > 0
--and it is detected from at least one of the binned images ???
and (G.flags & ( dbo.fPhotoFlags('BLENDED') + dbo.fPhotoFlags('NODEBLEND') + dbo.fPhotoFlags('CHILD'))) != dbo.fPhotoFlags('BLENDED')
--and, if it is blended, it is either a child or not deblended further ??
and (G.flags & (dbo.fPhotoFlags('EDGE') + dbo.fPhotoFlags('SATURATED'))) = 0
-- and it is not near a ccd edge or saturated, where measurements may be bad
and G.petroMag_i > 17.5
-- and it is fainter than 17.5 in i-band
and (G.petroMag_r > 15.5 or G.petror50_r > 2)
and (G.petroMag_r > 0 and G.g > 0 and G.r > 0 and G.i > 0)
and ( (G.petroMag_r - G.extinction_r) < 19.2
and (G.petroMag_r - G.extinction_r <
(13.1 + (7/3)*(G.g - G.r) + 4 *(G.r - G.i) - 4 * 0.18 ) )
and ( (G.r - G.i - (G.g - G.r)/4 - 0.18) < 0.2 )
and ( (G.r - G.i - (G.g - G.r)/4 - 0.18) > -0.2 ) )
or ( (G.petroMag_r - G.extinction_r < 19.5)
and ( (G.r - G.i - (G.g - G.r)/4 - 0.18) >
(0.45 - 4*(G.g - G.r) ) )
and ( (G.g - G.r) > (1.35 + 0.25 *(G.r - G.i) ) ) )
-- and many constraints on colors and mags are met to make it have
-- elliptical-type colors.
</textarea><textarea style="display:none" id="q_1400899770">-- Galaxies with bluer centers.
-- by Michael Strauss. For all galaxies
-- with r_Petro < 18, not saturated, not bright, and not edge, give me those
-- with centers appreciably bluer than their outer parts, i.e., define the
-- center color as: u_psf - g_psf and define the outer color as: u_model -
-- g_model; give me all objs which have (u_model - g_model) - (u_psf - g_psf)
-- < -0.4
-- Another flags-based query.
SELECT TOP 1000
colc_u, colc_g, objID
FROM Galaxy
WHERE
( Flags & (dbo.fPhotoFlags('SATURATED') +
dbo.fPhotoFlags('BRIGHT') +
dbo.fPhotoFlags('EDGE')) ) = 0
and petrorad_r < 18
and ((colc_u - colc_g) - (psfMag_u - psfMag_g)) < -0.4</textarea><textarea style="display:none" id="q_1330058026">-- Diameter-limited sample of galaxies
-- from James Annis.
SELECT TOP 1000
run,
camCol,
rerun,
field,
objID,
ra,
dec
FROM Galaxy
WHERE ( flags & (dbo.fPhotoFlags('BINNED1')
+ dbo.fPhotoFlags('BINNED2')
+ dbo.fPhotoFlags('BINNED4')) ) > 0
and ( flags & (dbo.fPhotoFlags('BLENDED')
+ dbo.fPhotoFlags('NODEBLEND')
+ dbo.fPhotoFlags('CHILD')) ) != dbo.fPhotoFlags('BLENDED')
and ( ( (flags & dbo.fPhotoFlags('NOPETRO') = 0)
and petrorad_i > 15)
or ( (flags & dbo.fPhotoFlags('NOPETRO') > 0)
and petrorad_i > 7.5)
or ( (flags & dbo.fPhotoFlags('TOO_LARGE') > 0)
and petrorad_i > 2.5)
or
( (flags & dbo.fPhotoFlags('SATURATED') = 0)
and petrorad_i > 17.5) )
</textarea><textarea style="display:none" id="q_1048676048">-- Extremely red galaxies.
-- from James Annis.
-- Similar to the diameter limited sample query.
SELECT TOP 1000
g.run,
g.camCol,
g.rerun,
g.field,
g.objID,
g.ra, g.dec
FROM Field f, Galaxy g
WHERE
g.fieldID = f.fieldID
and ( g.flags & (dbo.fPhotoFlags('BINNED1')
+ dbo.fPhotoFlags('BINNED2')
+ dbo.fPhotoFlags('BINNED4')) ) > 0
and ( g.flags & (dbo.fPhotoFlags('BLENDED')
+ dbo.fPhotoFlags('NODEBLEND')
+ dbo.fPhotoFlags('CHILD')) ) != dbo.fPhotoFlags('BLENDED')
and ( g.flags & (dbo.fPhotoFlags('COSMIC_RAY')
+ dbo.fPhotoFlags('INTERP')) ) = 0
and f.psfWidth_r < 1.5
and (g.i - g.z > 1.0 ) -- i and z in primary tables DO NOT include extinction</textarea><textarea style="display:none" id="q_53648337">-- A version of the LRG sample.
-- by James Annis.
-- Another query with many conditions and flag tests.
SELECT TOP 100
run,
camCol,
rerun,
field,
objID,
ra,
dec
FROM Galaxy
WHERE ( ( flags & (dbo.fPhotoFlags('BINNED1')
+ dbo.fPhotoFlags('BINNED2')
+ dbo.fPhotoFlags('BINNED4')) ) > 0
and ( flags & (dbo.fPhotoFlags('BLENDED')
+ dbo.fPhotoFlags('NODEBLEND')
+ dbo.fPhotoFlags('CHILD')) ) != dbo.fPhotoFlags('BLENDED')
and ( flags & (dbo.fPhotoFlags('EDGE')
+ dbo.fPhotoFlags('SATURATED')) ) = 0
and petroMag_i > 17.5
and (petroMag_r > 15.5 or petror50_r > 2)
and (petroMag_r > 0 and g > 0 and r > 0 and i > 0)
and ( (petroMag_r-extinction_r) < 19.2
and (petroMag_r - extinction_r <
(13.1 + (7/3) * (dered_g - dered_r) + 4 * (dered_r - dered_i) - 4 * 0.18) )
and ( (dered_r - dered_i - (dered_g - dered_r)/4 - 0.18) < 0.2)
and ( (dered_r - dered_i - (dered_g - dered_r)/4 - 0.18) > -0.2)
--dered_ quantities already include extinction
and ( (petroMag_r - extinction_r +
2.5 * LOG10(2 * 3.1415 * petror50_r * petror50_r)) < 24.2) )
or ( (petroMag_r - extinction_r < 19.5)
and ( (dered_r - dered_i - (dered_g - dered_r)/4 - 0.18) > (0.45 - 4 * (dered_g - dered_r)) )
and ( (dered_g - dered_r) > (1.35 + 0.25 * (dered_r - dered_i)) ) )
and ( (petroMag_r - extinction_r +
2.5 * LOG10(2 * 3.1415 * petror50_r * petror50_r) ) < 23.3 ) )</textarea><textarea style="display:none" id="q_1793902941">-- Find galaxies with specific spectra.
-- Namely, they have an equivalent width in
-- H_alpha > 40 Angstroms. We want object ID's from the photometry (Galaxy)
-- but constraints from spectroscopy. The line widths and IDs are stored in
-- SpecLine. --This is a simple query, but now we are using three tables. The
-- spectroscopy tables of measured lines are arranged non-intuitively, and we
-- urge users to read about them on the DAS help pages. --IMPORTANT NOTE:
-- Each spectroscopic object now has a match to at least two photometric
-- objects, one in Target and one in Best. Therefore, when performing a join
-- between spectroscopic photometric objects, you must specify either
-- PhotoObj.ObjID=SpecObj.bestObjID or PhotoObj.ObjID = SpecObj.targetObjID.
-- Normally, the default photometric database is BEST, so you will want to use
-- SpecObj.bestObjID
--
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT G.ObjID -- we want the photometric ObjID
FROM Galaxy as G, -- G is the galaxy
SpecObj as S, -- S is the spectra of galaxy G
SpecLine as L, -- L is a line of S
SpecLineNames as LN -- the names of the lines
WHERE G.ObjID = S.bestObjID -- connect the galaxy to the spectrum
and S.SpecObjID = L.SpecObjID -- and the spectral line L is detected in the spectrum
and L.LineId = LN.value -- L is the H alpha line
and LN.name = 'Ha_6565'
and L.ew > 40 -- and H alpha is at least 40 angstroms wide.
</textarea><textarea style="display:none" id="q_1876907516">-- Find galaxies with more specific spectra.
-- Same as prior query, but also require weak Hbeta line (Halpha/Hbeta > 20.)
--
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT G.ObjID -- return qualifying galaxies
FROM Galaxy as G, -- G is the galaxy
SpecObj as S, -- S is the spectra of galaxy G
SpecLine as L1, -- L1 is a line of S
SpecLine as L2, -- L2 is a second line of S
specLineNames as LN1, -- the names of the lines (Halpha)
specLineNames as LN2 -- the names of the lines (Hbeta)
WHERE G.ObjID = S.BestObjID -- connect the galaxy to the spectrum
and S.SpecObjID = L1.SpecObjID -- L1 is a line of S.
and S.SpecObjID = L2.SpecObjID -- L2 is a line of S.
and L1.LineId = LN1. value
and LN1.name = 'Ha_6565' -- L1 is the H alpha line
and L2.LineId = LN2.value -- L2 is the H alpha line
and LN2.name = 'Hb_4863' --
and L1.ew > 200 -- BIG Halpha
and L2.ew > 10 -- significant Hbeta emission line
and L2.ew * 20 < L1.ew -- Hbeta is comparatively small
</textarea><textarea style="display:none" id="q_1499026876">-- Find binary stars with specific colors.
-- At least one of them should have the colors of a white dwarf.
SELECT TOP 100 s1.objID as s1, s2.objID as s2
FROM Star S1, -- S1 is the white dwarf
Neighbors N, -- N is the precomputed neighbors links
Star S2 -- S2 is the second star
WHERE S1.objID = N. objID -- S1 and S2 are neighbors-within 30 arc sec
and S2.objID = N.NeighborObjID
and N.neighborType = dbo.fPhotoType('Star') -- and S2 is a star
and N.distance < .05 -- the 3 arcsecond test
and ((S1.u - S1.g) < 0.4 ) -- and S1 meets Paul Szkodys color cut for
and (S1.g - S1.r) < 0.7 -- white dwarfs.
and (S1.r - S1.i) > 0.4
and (S1.i - S1.z) > 0.4
</textarea><textarea style="display:none" id="q_253037019">-- Find quasars with a broad absorption line and a nearby galaxy.
-- within 10 arcseconds.
-- Return both the quasars and the galaxies.
--
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT Q.BestObjID as Quasar_candidate_ID , G.ObjID as Galaxy_ID, N.distance
FROM SpecObj as Q, -- Q is the specObj of the quasar candidate
Neighbors as N, -- N is the Neighbors list of Q
Galaxy as G, -- G is the nearby galaxy
SpecClass as SC, -- Spec Class
SpecLine as L, -- L is the broad line we are looking for
SpecLineNames as LN -- Line Name
WHERE Q.SpecClass =SC.value -- Q is a QSO
and SC.name in ('QSO', 'HIZ_QSO') -- Spectrum says "QSO"
and Q.SpecObjID = L.SpecObjID -- L is a spectral line of Q.
and L.LineID = LN.value -- line found and
and LN.Name != 'UNKNOWN' -- not not identified
and L.ew < -10 -- but its a prominent absorption line
and Q.BestObjID = N.ObjID -- N is a neighbor record
and G.ObjID = N.NeighborObjID -- G is a neighbor of Q
and N.distance < 10.0/60 -- and it is within 10 arcseconds of the Q.
</textarea><textarea style="display:none" id="q_627065552">-- Find galaxies without saturated pixels within 1' of a given point.
-- ra=185.0, dec=-0.5. This query uses a function fGetNearbyObjEq,
-- which takes 3 arguments (ra,dec, distance in arcmin); this function uses
-- the Neighbors table. The Neighbors table and the Galaxy table have in
-- common the objID, so we have to select objects from both where the objIDs
-- are the same. The output of the function is a table with the Galaxy Object
-- ID and distance in arcmin from the input. This query introduces the use of
-- a JOIN to combine table contents. Also, we use the 'orDER BY' syntax,
-- which will sort the output.
SELECT TOP 100 G.objID, GN.distance
FROM Galaxy as G
JOIN dbo.fGetNearbyObjEq(185.,-0.5, 1) as GN -- this function outputs a table, so we have to do a join
on G.objID = GN.objID -- get objects from temporary neighbors table GN with desired ObjID
WHERE (G.flags & dbo.fPhotoFlags('saturated')) = 0 -- and the object is not saturated. f.PhotoFlags is a function that interprets the flag bits.
ORDER BY distance -- sort these by distance
</textarea><textarea style="display:none" id="q_873473743">-- Ellipticals with odd lines.
-- Find all elliptical galaxies with spectra that have an anomalous
-- emission line. This query introduces the SQL syntax DISTINCT, which will
-- return only one instance of the requested parameter (ObjID, in this case),
-- because our query may return the same object more than once. This is also
-- the first nested query, where we use one SELECT (the inner one) to get a
-- group of objects we are not interested in. The outer SELECT includes the
-- new syntax 'not in', which is used to perform the exclusion.
--
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT DISTINCT G.ObjID -- return qualifying galaxies
FROM
Galaxy as G, -- G is the galaxy
SpecObjAll as S, -- S is the spectra of galaxy G
SpecLineAll as L, -- L is a line of S
-- we must use SpecLineAll because SpecLine only has ID's lines
XCRedshift as XC -- the template cross-correlation redshift
WHERE G.ObjID = S.bestObjID -- connect galaxy to the spectrum
and S.SpecObjID = L.SpecObjID -- The line L must be in the spectrum S
and S.SpecObjID = XC.SpecObjID -- and there is a crosscorrelation redshift
and XC.tempNo = 8 -- Template('Elliptical') -- best Cross correlation template used is "elliptical"
and L.LineID = 0
and L.ew > 10 -- and the line is prominent by some definition, in this case, the equivalent width is over 10 Angstroms
and S.SpecObjID not in (
-- insist that there are no other lines
SELECT S.SpecObjID -- This is the chosen line.
FROM SpecLine as L1 -- L1 is another line...
-- by using SpecLine, we are automatically requiring that the line
-- be identified
WHERE S.SpecObjID = L1.SpecObjID -- ...for this object...
and abs(L.wave - L1.wave) <.01
-- ...at nearly the same wavelength...
)
</textarea><textarea style="display:none" id="q_1226072052">-- Search near BCG galaxies.
-- For each galaxy in the BCG data set (brightest cluster galaxy),
-- in 160<right ascension<170, -25<declination<35 count the number of
-- galaxies within 30" of it that have a photoz within 0.05
-- of that galaxy.
-- An extremely complex WHERE clause.
SELECT G.objID, count(N.NeighborObjID) as pop
FROM Galaxy as G, -- first gravitational lens candidate
Neighbors as N, -- precomputed list of neighbors
Galaxy as U, -- a neighbor galaxy of G
photoZ as Gpz, -- photoZ of G.
photoZ as Npz -- Neighbor photoZ
WHERE G.ra between 160 and 170
and G.dec between -5 and 5
and G.objID = N.objID -- connect G and U via the neighbors table
and U.objID = N.neighborObjID -- so that we know G and U are within
and N.objID < N.neighborObjID -- 30 arcseconds of one another.
and G.objID = Gpz.objID
and U.objID = Npz.objID
and abs(Gpz.Z - Npz.Z) < 0.05 -- restrict the photoZ differences
and (G.flags & (dbo.fPhotoFlags('BINNED1') + dbo.fPhotoFlags('BINNED2') + dbo.fPhotoFlags('BINNED4'))) > 0
--and it is detected from at least one of the binned images
and (G.flags & ( dbo.fPhotoFlags('BLENDED') + dbo.fPhotoFlags('NODEBLEND') + dbo.fPhotoFlags('CHILD'))) != dbo.fPhotoFlags('BLENDED')
--and, if it is blended, it is either a child or not deblended further ??
and (G.flags & (dbo.fPhotoFlags('EDGE') + dbo.fPhotoFlags('SATURATED'))) = 0
-- and it is not near a ccd edge or saturated, where measurements may be bad
-- and apply color cut for a BCG courtesy of James Annis of Fermilab
and G.petroMag_i > 17.5
and (G.petroMag_r > 15.5 or G.petror50_r > 2)
and (G.petroMag_r < 30 and G.g < 30 and G.r < 30 and G.i < 30)
and (G.r < 19.2
and ( 1=1 or -- huh?
(G.r < (13.1 + (7/3)*(G.g - G.r) +
-- deRed_r < 13.1 + 0.7 / 0.3 * deRed_gr
4 *(G.r - G.i - 0.18 ))
-- 1.2 / 0.3 * deRed_ri
and (( G.r - G.i - (G.g - G.r)/4 - 0.18) BETWEEN -0.2 and 0.2 )
and ((G.r +
-- petSB - deRed_r + 2.5 log10(2Pi*petror50^2)
2.5 * LOG( 2 * 3.1415 * G.petror50_r * G.petror50_r )) < 24.2 )
)
or
( (G.r < 19.5 )
and (( G.r - G.i -(G.g - G.r)/4 -.18) >
-- - deRed_gr/4 - 0.18
-- cperp = deRed_ri
(0.45 - 4*( G.g - G.r)))
-- 0.45 - deRed_gr/0.25
and ((G.g - G.r) > ( 1.35 + 0.25 *(G.r - G.i)))
and ((G.r +
-- petSB - deRed_r + 2.5 log10(2Pi*petror50^2)
2.5 * LOG( 2 * 3.1415 * G.petror50_r * G.petror50_r )) < 23.3 )
)) )
group by G.objID
</textarea><textarea style="display:none" id="q_1201934799">-- Broadest line of each spectrum with its ID.
-- (or more generally, all the columns for
-- the spectral line with the highest/lowest something)? The line width is
-- stored in the column sigma, the identification is in the column restwave.
-- (Sebastian Jester )
--
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT
L.specObjId,
L.specLineID,
sMax.Maxwidth -- get the spectroscopic object ID, the line ID, and the width
FROM specLine L,
(SELECT specObjID,
Max(waveMax-waveMin) as MaxWidth
-- Define MaxWidth as the largest difference in the min and max wavelength of
-- an identified line, using the built-in Max function of SQL
FROM SpecLine
GROUP BY specObjID) as sMax
-- sMax contains a single specObjID and MaxWidth. Remember that for each line
-- identified in a given object's spectrum, there is an entry in
-- SpecLine. This means that each specObjID appears many times in SpecLine,
-- once for each line found, and they must be aggregated before performing any
-- operation such as Max. The GROUP BY is thus NECESSARY.
-- The upper FROM clause is telling us we will use the table SpecLine and this
-- new output called sMax, which contains one entry with the SpecObjID and
-- MaxWidth. If we used some other function instead of 'Max', such as 'top
-- 10', sMax would have more than row.
WHERE
L.specObjID = sMax.specObjID
and (L.waveMax-L.waveMin) = sMax.MaxWidth
-- Just as with the specObjID, each specLineID appears many times in specLine.
-- This final WHERE clause makes sure we get the one specLineID from SpecObj
-- which matches the unique combination of specObjID and MaxWidth in sMax.
</textarea><textarea style="display:none" id="q_1778610482">-- Gridded galaxy counts and masks. Actually consists of TWO queries:
-- 1) Create a gridded count of galaxies with u-g > 1 and r < 21.5 over -1 < dec < 1,
-- and 179 < R.A. < 181, on a grid, and create a map of masks over the same grid.
-- Scan the table for galaxies and group them in cells 2 arc-minuteson a side. Provide
-- predicates for the color restrictions on u-g and r and to limit the search to the
-- portion of the sky defined by the right ascension and declination conditions. Return
-- the count of qualifying galaxies in each cell.
-- 2) Run another query with the same grouping, but with a predicate to include only
-- objects such as satellites, planets, and airplanes that obscure the cell. The second
-- query returns a list of cell coordinates that serve as a mask for the first query.
--- First find the gridded galaxy count (with the color cut)
--- In local tangent plane, ra/cos(dec) is a linear degree.
SELECT cast((ra/cos(cast(dec*30 as int)/30.0))*30 as int)/30.0 as raCosDec,
cast(dec*30 as int)/30.0 as dec,
count(*) as pop
FROM Galaxy as G
JOIN dbo.fHTMCoverRegion('CHULL J2000 179 -1 179 1 181 1 181 -1') AS T
ON G.htmID BETWEEN T.HTMIDstart AND T. HTMIDend
WHERE ra between 179 and 181
and dec between -1 and 1
and u-g > 1
and r < 21.5
GROUP BY cast((ra/cos(cast(dec*30 as int)/30.0))*30 as int)/30.0,
cast(dec*30 as int)/30.0
-- now build mask grid.
-- This is a separate query if no temp tables can be made
SELECT cast((ra/cos(cast(dec*30 as int)/30.0))*30 as int)/30.0 as raCosDec,
cast(dec*30 as int)/30.0 as dec,
count(*) as pop
FROM PhotoObj as PO
JOIN dbo.fHTMCoverRegion('CHULL J2000 179 -1 179 1 181 1 181 -1') AS T
ON PO.htmID BETWEEN T.HTMIDstart AND T.HTMIDend
JOIN PhotoType as PT ON PO.type = PT.value
WHERE
ra between 179 and 181
and dec between -1 and 1
and PT.name in ('COSMIC_RAY', 'DEFECT', 'GHOST', 'TRAIL', 'UNKNOWN')
GROUP BY cast((ra/cos(cast(dec*30 as int)/30.0))*30 as int)/30.0,
cast(dec*30 as int)/30.0 </textarea><textarea style="display:none" id="q_2026496616">-- Create a count of galaxies for each of the HTM triangles.
-- Galaxies should satisfy a certain color cut,
-- like 0.7u-0.5g-0.2i<1.25 && r<21.75, output it in a form
-- adequate for visualization.
SELECT (htmID / power(2,24)) as htm_8 ,
-- group by 8-deep HTMID (rshift HTM by 12)
avg(ra) as ra,
avg(dec) as [dec],
count(*) as pop -- return center point and count for display
FROM Galaxy -- only look at galaxies
WHERE (0.7*u - 0.5*g - 0.2*i) < 1.25 -- meeting this color cut
and r < 21.75 -- brighter than 21.75 magnitude in red band.
group by (htmID /power(2,24)) -- group into 8-deep HTM buckets.
</textarea><textarea style="display:none" id="q_813213932">-- Find stars with multiple measurements with magnitude variations >0.1.
-- Note that this runs very slowly unless explicit workarounds are included
-- for some SQLServer Optimizer bugs, which are NOT included here
SELECT TOP 100
S1.objID as objID1, S2.objID as ObjID2 -- select object IDs of star and its pair
FROM Star as S1, -- the primary star
photoObj as S2, -- the second observation of the star
neighbors as N -- the neighbor record
WHERE S1.objID = N.objID -- insist the stars are neighbors
and S2.objID = N.neighborObjID -- using precomputed neighbors table
and distance < 0.5/60 -- distance is 0.5 arc second or less
and S1.run != S2.run -- observations are two different runs
and S2.type = dbo.fPhotoType('Star') -- S2 is indeed a star
and S1.u between 1 and 27 -- S1 magnitudes are reasonable
and S1.g between 1 and 27
and S1.r between 1 and 27
and S1.i between 1 and 27
and S1.z between 1 and 27
and S2.u between 1 and 27 -- S2 magnitudes are reasonable.
and S2.g between 1 and 27
and S2.r between 1 and 27
and S2.i between 1 and 27
and S2.z between 1 and 27
and ( -- and one of the colors is different.
abs(S1.u-S2.u) > .1 + (abs(S1.Err_u) + abs(S2.Err_u))
or abs(S1.g-S2.g) > .1 + (abs(S1.Err_g) + abs(S2.Err_g))
or abs(S1.r-S2.r) > .1 + (abs(S1.Err_r) + abs(S2.Err_r))
or abs(S1.i-S2.i) > .1 + (abs(S1.Err_i) + abs(S2.Err_i))
or abs(S1.z-S2.z) > .1 + (abs(S1.Err_z) + abs(S2.Err_z))
)
</textarea><textarea style="display:none" id="q_1470069848">-- This query uses the new SQL Server 2005 CROSS APPLY and OUTER APPLY
-- constructs to apply a table-valued function to the results of a query.
-- In this example, we use the fFootPrintEq function which returns a list
-- of SDSS regions that intersect the area specified by the RA, dec and
-- radius, or NULL if the area is outside the SDSS footprint.
-- For each point in the input list, in this case the result of a query
-- on PhotoObj, return "yes" or "no" depending on whether the point is in
-- the SDSS footprint or not, and any other needed columns.
SELECT top 100 objID, ra, dec,
(case when p.type is null then 'NO' else 'YES' end) as found
FROM PhotoObj AS p
OUTER APPLY dbo.fFootprintEq(ra,dec,0.1)
WHERE (ra between 179.5 and 182.3) and (dec between -1.0 and 1.8)
</textarea>
<textarea style="display:none" id="q_1442356757">-- Basic_SELECT_FROM_WHERE
-- Find objects in a particular field.
SELECT objID,
field, ra, dec -- Get the unique object ID, field number, and coords
FROM PhotoObj -- From the photometric data
WHERE fieldID = 587722951961673728 -- that is in a specific field
</textarea><textarea style="display:none" id="q_25768111">-- Galaxies meeting two simple criteria.
-- Find all galaxies brighter than r magnitude 17, where the local
-- extinction is > 0.275. This is a simple query that uses a WHERE clause,
-- but now two conditions that must be met simultaneously.
--
-- Finds 6604 galaxies in under 10 mins on DR2, but beware that increasing
-- the limiting r magnitude will significantly add to the execution time.
SELECT objID
FROM Galaxy
WHERE
r < 17 -- r IS NOT deredenned
and extinction_r > 0.275 -- extinction more than 0.175
</textarea><textarea style="display:none" id="q_836207046">-- Find all objects with unclassified spectra.
-- A simple SELECT-FROM-WHERE query, using a function
--
-- On DR2, returns 3109 rows in 20 sec.
SELECT specObjID
FROM SpecObj
WHERE SpecClass = dbo.fSpecClass('UNKNOWN')</textarea><textarea style="display:none" id="q_1444654077">-- Galaxies meeting multiple simple criteria.
-- Find all galaxies with blue surface brightness between 23 and 25
-- mag per square arcseconds, and -10 < supergalactic latitude (sgb) < 10, and
-- declination less than zero. Currently, we have to live with ra/dec until we
-- get galactic coordinates. To calculate surface brightness per sq. arcsec,
-- we use (g + rho), where g is the blue magnitude, and rho= 5*log(r). This
-- query now has three requirements, one involving simple math.
--
-- On DR2, returns 61090 rows in 330 sec.
SELECT objID
FROM Galaxy
WHERE ra between 178 and 180
and dec < 0
-- and (g+rho) between 23 and 25
and g between (23-rho) and (25-rho)
-- g is the blue magnitude, and rho= 5*log(Petro radius)</textarea><textarea style="display:none" id="q_824393739">-- Using spatial unit vectors for coordinate cuts.
-- Find galaxies in a given area of the sky, using a coordinate cut
-- in the unit vector cx,cy,cz that corresponds to a specific RA range.
-- Another simple query that uses math in the WHERE clause.
--
-- Finds 100 galaxies in 230 sec on DR2, but this is a very slow way to do
-- coordinate cuts. Using RA/dec is *much* faster due to indexing.
--
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT TOP 100 colc_g, colc_r
FROM Galaxy
WHERE
(-0.466 * cx + 0.689 * cy>=0)
and (-0.385 * cx - 0.173 * cy <0)
</textarea><textarea style="display:none" id="q_1467158080">-- Find CVs using colors.
-- Search for Cataclysmic Variables and pre-CVs with White Dwarfs and
-- very late secondaries. Just uses some simple color cuts from Paula Szkody.
-- Another simple query that uses math in the WHERE clause
--
-- Finishes in 72 sec on DR2.
SELECT TOP 10000 run,
camCol,
rerun,
field,
objID,
u, g, r, i, z,
ra, dec -- Just get some basic quantities
FROM PhotoPrimary -- From all primary detections, regardless of class
WHERE u - g < 0.4
and g - r < 0.7
and r - i > 0.4
and i - z > 0.4 -- that meet the color criteria
</textarea><textarea style="display:none" id="q_922576218">-- Getting a subsample of the data.
-- Uses the integer short object id (obj) and the '%' syntax (like awk)
-- to get every 1000th object. THIS IS NOT A TRULY RANDOM SUBSET!
--
-- Returns 11367 objects in DR2 (in about 10-15mins).
SELECT u, g, r, i, z
FROM Galaxy with (nolock)
WHERE (objID%1000) = 1
AND (r between 18 and 21)
</textarea><textarea style="display:none" id="q_256345731">-- Low-z QSO candidates using color cuts.
-- from Gordon Richards.
-- Also a simple query with a long WHERE clause.
SELECT TOP 1000 g, run, rerun, camcol, field, objID
FROM
Galaxy
WHERE (
(g <= 22) and
(u-g >= -0.27) and (u-g < 0.71) and
(g-r >= -0.24) and (g-r < 0.35) and
(r-i >= -0.27) and (r-i < 0.57) and
(i-z >= -0.35) and (i-z < 0.70)
)</textarea><textarea style="display:none" id="q_1261782764">-- Get object velocities and errors.
-- This is also a simple query that uses a WHERE clause.
-- However, now we perform a more complex mathematical operation.
SELECT TOP 1000
run, -- get a bunch of quantities
camCol,
field,
objID,
rowC, colC, rowV, colV, rowVErr, colVErr,
flags,
psfMag_u, psfMag_g, psfMag_r, psfMag_i, psfMag_z,
psfMagErr_u, psfMagErr_g, psfMagErr_r, psfMagErr_i, psfMagErr_z
FROM PhotoPrimary
WHERE ((rowv * rowv) / (rowvErr * rowvErr) +
(colv * colv) / (colvErr * colvErr) > 4)
-- where the velocities are reliable
</textarea><textarea style="display:none" id="q_1772065995">-- Using the BETWEEN syntax.
-- Find galaxies with an isophotal surface brightness (SB) larger
-- than 24 in the red band, and with an ellipticity > 0.5, and with the major
-- axis of the ellipse having a declination between 30" and 60" arc seconds.
-- This is also a simple query that uses a WHERE clause with three conditions
-- that must be met. We introduce the syntax 'BETWEEN' to do a range search.
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT TOP 100 ObjID
FROM Galaxy
WHERE r < 24 - rho
-- surface brightness brighter than 24 mag. per sq. arcsec in the red
-- Note that isolating r (indexed) on one side helps this run faster
and isoA_r between 30 and 60
-- major axis between 30" and 60"
and (power(q_r,2) + power(u_r,2)) > 0.25
-- square of ellipticity is > 0.5 squared. The SQL term 'power' is used for exponentiation.</textarea><textarea style="display:none" id="q_731851157">-- Moving objects consistent with an asteroid.
-- Also a simple query, but we introduce the 'as' syntax, which allows us to
-- name derived quantities in the result file.
--
--This Sample Query will not work for SDSS3 contexts
SELECT TOP 10
objID,
sqrt( power(rowv,2) + power(colv, 2) ) as velocity
FROM PhotoObj
WHERE
(power(rowv,2) + power(colv, 2)) between 50 and 1000
</textarea><textarea style="display:none" id="q_197942948">-- Find quasars in imaging data.
-- as specified by Xiaohui Fan et.al.
-- A rather straightforward query, just with many conditions.
SELECT TOP 1000 run,
camCol,
rerun,
field,
objID,
u, g, r, i, z,
ra, dec
FROM Star -- or Galaxy
WHERE ( u - g > 2.0 or u > 22.3 )
and ( i < 19 )
and ( i > 0 )
and ( g - r > 1.0 )
and ( r - i <
(0.08 + 0.42 * (g - r - 0.96) )
or g - r > 2.26 )
and ( i - z < 0.25 )
</textarea><textarea style="display:none" id="q_307791979">-- Using object counting and logic in a query.
-- Find all objects similar to the colors of a quasar at 5.5<redshift<6.5.
SELECT count(*) as 'total',
sum( case when (Type=3) then 1 else 0 end) as 'Galaxies',
sum( case when (Type=6) then 1 else 0 end) as 'Stars',
sum( case when (Type not in (3,6)) then 1 else 0 end) as 'Other'
FROM PhotoPrimary -- for each object
WHERE (( u - g > 2.0) or (u > 22.3) ) -- apply the quasar color cut.
and ( i between 0 and 19 )
and ( g - r > 1.0 )
and ( (r - i < 0.08 + 0.42 * (g - r - 0.96)) or (g - r > 2.26 ) )
and ( i - z < 0.25 )
</textarea><textarea style="display:none" id="q_663453829">-- Find galaxies that are blended with a star.
-- Output the deblended galaxy magnitudes.
-- This query introduces the use of multiple tables or views. You can assign
-- nicknames to tables as in the FROM clause below. Since you are using
-- multiple tables, you ,ust specify which table each quantity in the SELECT
-- clause comes from. Finally, the last line in the query is the join between
-- the two tables, which is achieved by requiring that a quantity present in
-- both tables be equal.
-- NOTE: This query times out (takes too long) without the "TOP 1000".
SELECT top 1000 G.ObjID, G.u, G.g, G.r, G.i, G.z --get the ObjID and final mags
FROM Galaxy G, Star S -- use two Views, Galaxy and Star, as a convenient mechanism to compare objects
WHERE G.parentID > 0 -- galaxy has a "parent", which tells us this object was deblended
and G.parentID = S.parentID -- and the star has the same parent
</textarea><textarea style="display:none" id="q_1970118298">-- Stars selected using Field criteria.
-- Give me the PSF colors of all stars brighter than g=20 that have PSP_STATUS = 2.
-- Another simple multi-table query.
SELECT TOP 1000
s.psfMag_g, -- or whatever you want from each object
s.run,
s.camCol,
s.rerun,
s.field
FROM Star s, Field f
WHERE s.fieldID = f.fieldID
and s.psfMag_g < 20
and f.pspStatus = 2</textarea><textarea style="display:none" id="q_1322104004">-- Objects selected by cuts on three tables.
-- Find the parameters for all objects in a selected field with
-- desired PSF width and range of columns.
-- Now we are using three tables, but it is still a simple query.
-- NOTE: This query times out (takes too long) without the "TOP 1000".
SELECT TOP 1000
f.run,
f.rerun,
f.camCol,
f.field,
p.objID,
p.ra,
p.dec,
p.Rowc,
p.Colc,
p.u,
p.modelMagErr_u ,
p.g,
p.modelMagErr_g,
p.r,
p.modelMagErr_r,
p.petroMag_r - p.extinction_r,
p.petroMagErr_r,
p.i,
p.modelMagErr_i,
p.z,
f.psfWidth_r
FROM
photoObj p, field f
WHERE
f.fieldid = p.fieldid
and f.psfWidth_r > 1.2
and p.colc > 400.0
</textarea><textarea style="display:none" id="q_488717385">-- Find all objects within 30 arcseconds of one another
-- that have very similar colors: that is where the color ratios
-- u-g, g-r, r-I are less than 0.05m.
SELECT TOP 10 P.ObjID -- distinct cases
FROM PhotoPrimary P, -- P is the primary object
Neighbors N, -- N is the neighbor link
PhotoPrimary L -- L is the lens candidate of P
WHERE P.ObjID = N.ObjID -- N is a neighbor record
and L.ObjID = N.NeighborObjID -- L is a neighbor of P
and P.ObjID < L. ObjID -- avoid duplicates
and abs((P.u-P.g)-(L.u-L.g))<0.05 -- L and P have similar spectra.
and abs((P.g-P.r)-(L.g-L.r))<0.05
and abs((P.r-P.i)-(L.r-L.i))<0.05
and abs((P.i-P.z)-(L.i-L.z))<0.05
</textarea><textarea style="display:none" id="q_666094160">-- Find specific types of quasars using spectroscopy.
-- The easiest way to find quasars is by finding objects whose spectra have
-- been classified as quasars. This sample query searches the SpecObj
-- table for the IDs and redshifts of objects with the class column equal to 'QSO'
SELECT TOP 100 specObjID, z
FROM SpecObj
WHERE class = 'QSO' AND zWarning = 0
</textarea><textarea style="display:none" id="q_1391190496">-- Checking for errors using flags.
-- Another useful query is to see if the errors on moving (or
-- apparently moving) objects are correct. For example, it used to be that
-- some known QSOs were being flagged as moving objects. One way to look for
-- such objects is to compare the velocity to the error in velocity and see if
-- the "OBJECT1_MOVED" or "OBJECT2_BAD_MOVING_FIT" is set.
-- This query introduces bitwise logic for flags, and uses the 'as' syntax to
-- make the query more readable. Note that if a flag is not set, the value
-- will be zero. If you want to ensure multiple flags are not set, you can
-- either check that each individually is zero, or their sum is zero.
-- (From Gordon Richards)
SELECT TOP 1000
run,
rerun,
camcol,
field,
objID,
ra, dec,
rowv, colv,
rowvErr, colvErr,
i,
(flags & dbo.fPhotoFlags('MOVED')) as MOVED,
(flags & dbo.fPhotoFlags('BAD_MOVING_FIT')) as BAD_MOVING_FIT
FROM Galaxy
WHERE
(flags & (dbo.fPhotoFlags('MOVED') + dbo.fPhotoFlags('BAD_MOVING_FIT'))) > 0
and (rowv * rowv + colv * colv) >=
(rowvErr * rowvErr + colvErr * colvErr)</textarea><textarea style="display:none" id="q_12263065">-- Elliptical galaxies based on model fits.
-- Find all galaxies with a deVaucouleours profile and the
-- photometric colors consistent with an elliptical galaxy. NOTE THAT THE
-- NAMES and VALUES OF THE LIKELIHOODS HAVE CHANGED SINCE THE EDR; they are
-- now log likelihoods, and named accordingly (lDev is now lnlDev, etc.) to
-- indicate these are log likelihoods. This query has many conditions, and
-- also has the use of bitwise logic necessary for dealing with flags.
SELECT TOP 100 ObjID
FROM Galaxy as G
WHERE
G.lnlDev_r > G.lnlExp_r + 0.1
-- the likelihood of the deVaucouleours profile fit is 10% greater than the likelihood of the exponential fit
and G.lnlExp_r > -999
-- and the likelihoods are actually meaningful
and (G.flags & (dbo.fPhotoFlags('BINNED1') + dbo.fPhotoFlags('BINNED2') + dbo.fPhotoFlags('BINNED4'))) > 0
--and it is detected from at least one of the binned images ???
and (G.flags & ( dbo.fPhotoFlags('BLENDED') + dbo.fPhotoFlags('NODEBLEND') + dbo.fPhotoFlags('CHILD'))) != dbo.fPhotoFlags('BLENDED')
--and, if it is blended, it is either a child or not deblended further ??
and (G.flags & (dbo.fPhotoFlags('EDGE') + dbo.fPhotoFlags('SATURATED'))) = 0
-- and it is not near a ccd edge or saturated, where measurements may be bad
and G.petroMag_i > 17.5
-- and it is fainter than 17.5 in i-band
and (G.petroMag_r > 15.5 or G.petror50_r > 2)
and (G.petroMag_r > 0 and G.g > 0 and G.r > 0 and G.i > 0)
and ( (G.petroMag_r - G.extinction_r) < 19.2
and (G.petroMag_r - G.extinction_r <
(13.1 + (7/3)*(G.g - G.r) + 4 *(G.r - G.i) - 4 * 0.18 ) )
and ( (G.r - G.i - (G.g - G.r)/4 - 0.18) < 0.2 )
and ( (G.r - G.i - (G.g - G.r)/4 - 0.18) > -0.2 ) )
or ( (G.petroMag_r - G.extinction_r < 19.5)
and ( (G.r - G.i - (G.g - G.r)/4 - 0.18) >
(0.45 - 4*(G.g - G.r) ) )
and ( (G.g - G.r) > (1.35 + 0.25 *(G.r - G.i) ) ) )
-- and many constraints on colors and mags are met to make it have
-- elliptical-type colors.
</textarea><textarea style="display:none" id="q_1540682795">-- Galaxies with bluer centers.
-- by Michael Strauss. For all galaxies
-- with r_Petro < 18, not saturated, not bright, and not edge, give me those
-- with centers appreciably bluer than their outer parts, i.e., define the
-- center color as: u_psf - g_psf and define the outer color as: u_model -
-- g_model; give me all objs which have (u_model - g_model) - (u_psf - g_psf)
-- < -0.4
-- Another flags-based query.
SELECT TOP 1000
colc_u, colc_g, objID
FROM Galaxy
WHERE
( Flags & (dbo.fPhotoFlags('SATURATED') +
dbo.fPhotoFlags('BRIGHT') +
dbo.fPhotoFlags('EDGE')) ) = 0
and petrorad_r < 18
and ((colc_u - colc_g) - (psfMag_u - psfMag_g)) < -0.4</textarea><textarea style="display:none" id="q_1674685583">-- Diameter-limited sample of galaxies
-- from James Annis.
SELECT TOP 1000
run,
camCol,
rerun,
field,
objID,
ra,
dec
FROM Galaxy
WHERE ( flags & (dbo.fPhotoFlags('BINNED1')
+ dbo.fPhotoFlags('BINNED2')
+ dbo.fPhotoFlags('BINNED4')) ) > 0
and ( flags & (dbo.fPhotoFlags('BLENDED')
+ dbo.fPhotoFlags('NODEBLEND')
+ dbo.fPhotoFlags('CHILD')) ) != dbo.fPhotoFlags('BLENDED')
and ( ( (flags & dbo.fPhotoFlags('NOPETRO') = 0)
and petrorad_i > 15)
or ( (flags & dbo.fPhotoFlags('NOPETRO') > 0)
and petrorad_i > 7.5)
or ( (flags & dbo.fPhotoFlags('TOO_LARGE') > 0)
and petrorad_i > 2.5)
or
( (flags & dbo.fPhotoFlags('SATURATED') = 0)
and petrorad_i > 17.5) )
</textarea><textarea style="display:none" id="q_335683413">-- Extremely red galaxies.
-- from James Annis.
-- Similar to the diameter limited sample query.
SELECT TOP 1000
g.run,
g.camCol,
g.rerun,
g.field,
g.objID,
g.ra, g.dec
FROM Field f, Galaxy g
WHERE
g.fieldID = f.fieldID
and ( g.flags & (dbo.fPhotoFlags('BINNED1')
+ dbo.fPhotoFlags('BINNED2')
+ dbo.fPhotoFlags('BINNED4')) ) > 0
and ( g.flags & (dbo.fPhotoFlags('BLENDED')
+ dbo.fPhotoFlags('NODEBLEND')
+ dbo.fPhotoFlags('CHILD')) ) != dbo.fPhotoFlags('BLENDED')
and ( g.flags & (dbo.fPhotoFlags('COSMIC_RAY')
+ dbo.fPhotoFlags('INTERP')) ) = 0
and f.psfWidth_r < 1.5
and (g.i - g.z > 1.0 ) -- i and z in primary tables DO NOT include extinction</textarea><textarea style="display:none" id="q_1986785076">-- A version of the LRG sample.
-- by James Annis.
-- Another query with many conditions and flag tests.
SELECT TOP 100
run,
camCol,
rerun,
field,
objID,
ra,
dec
FROM Galaxy
WHERE ( ( flags & (dbo.fPhotoFlags('BINNED1')
+ dbo.fPhotoFlags('BINNED2')
+ dbo.fPhotoFlags('BINNED4')) ) > 0
and ( flags & (dbo.fPhotoFlags('BLENDED')
+ dbo.fPhotoFlags('NODEBLEND')
+ dbo.fPhotoFlags('CHILD')) ) != dbo.fPhotoFlags('BLENDED')
and ( flags & (dbo.fPhotoFlags('EDGE')
+ dbo.fPhotoFlags('SATURATED')) ) = 0
and petroMag_i > 17.5
and (petroMag_r > 15.5 or petror50_r > 2)
and (petroMag_r > 0 and g > 0 and r > 0 and i > 0)
and ( (petroMag_r-extinction_r) < 19.2
and (petroMag_r - extinction_r <
(13.1 + (7/3) * (dered_g - dered_r) + 4 * (dered_r - dered_i) - 4 * 0.18) )
and ( (dered_r - dered_i - (dered_g - dered_r)/4 - 0.18) < 0.2)
and ( (dered_r - dered_i - (dered_g - dered_r)/4 - 0.18) > -0.2)
--dered_ quantities already include extinction
and ( (petroMag_r - extinction_r +
2.5 * LOG10(2 * 3.1415 * petror50_r * petror50_r)) < 24.2) )
or ( (petroMag_r - extinction_r < 19.5)
and ( (dered_r - dered_i - (dered_g - dered_r)/4 - 0.18) > (0.45 - 4 * (dered_g - dered_r)) )
and ( (dered_g - dered_r) > (1.35 + 0.25 * (dered_r - dered_i)) ) )
and ( (petroMag_r - extinction_r +
2.5 * LOG10(2 * 3.1415 * petror50_r * petror50_r) ) < 23.3 ) )</textarea><textarea style="display:none" id="q_279312168">-- Find galaxies with specific spectra.
-- Namely, they have an equivalent width in
-- H_alpha > 40 Angstroms. We want object ID's from the photometry (Galaxy)
-- but constraints from spectroscopy. The line widths and IDs are stored in
-- SpecLine. --This is a simple query, but now we are using three tables. The
-- spectroscopy tables of measured lines are arranged non-intuitively, and we
-- urge users to read about them on the DAS help pages. --IMPORTANT NOTE:
-- Each spectroscopic object now has a match to at least two photometric
-- objects, one in Target and one in Best. Therefore, when performing a join
-- between spectroscopic photometric objects, you must specify either
-- PhotoObj.ObjID=SpecObj.bestObjID or PhotoObj.ObjID = SpecObj.targetObjID.
-- Normally, the default photometric database is BEST, so you will want to use
-- SpecObj.bestObjID
--
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT G.ObjID -- we want the photometric ObjID
FROM Galaxy as G, -- G is the galaxy
SpecObj as S, -- S is the spectra of galaxy G
SpecLine as L, -- L is a line of S
SpecLineNames as LN -- the names of the lines
WHERE G.ObjID = S.bestObjID -- connect the galaxy to the spectrum
and S.SpecObjID = L.SpecObjID -- and the spectral line L is detected in the spectrum
and L.LineId = LN.value -- L is the H alpha line
and LN.name = 'Ha_6565'
and L.ew > 40 -- and H alpha is at least 40 angstroms wide.
</textarea><textarea style="display:none" id="q_168810913">-- Find galaxies with more specific spectra.
-- Same as prior query, but also require weak Hbeta line (Halpha/Hbeta > 20.)
--
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT G.ObjID -- return qualifying galaxies
FROM Galaxy as G, -- G is the galaxy
SpecObj as S, -- S is the spectra of galaxy G
SpecLine as L1, -- L1 is a line of S
SpecLine as L2, -- L2 is a second line of S
specLineNames as LN1, -- the names of the lines (Halpha)
specLineNames as LN2 -- the names of the lines (Hbeta)
WHERE G.ObjID = S.BestObjID -- connect the galaxy to the spectrum
and S.SpecObjID = L1.SpecObjID -- L1 is a line of S.
and S.SpecObjID = L2.SpecObjID -- L2 is a line of S.
and L1.LineId = LN1. value
and LN1.name = 'Ha_6565' -- L1 is the H alpha line
and L2.LineId = LN2.value -- L2 is the H alpha line
and LN2.name = 'Hb_4863' --
and L1.ew > 200 -- BIG Halpha
and L2.ew > 10 -- significant Hbeta emission line
and L2.ew * 20 < L1.ew -- Hbeta is comparatively small
</textarea><textarea style="display:none" id="q_1868611009">-- Find binary stars with specific colors.
-- At least one of them should have the colors of a white dwarf.
SELECT TOP 100 s1.objID as s1, s2.objID as s2
FROM Star S1, -- S1 is the white dwarf
Neighbors N, -- N is the precomputed neighbors links
Star S2 -- S2 is the second star
WHERE S1.objID = N. objID -- S1 and S2 are neighbors-within 30 arc sec
and S2.objID = N.NeighborObjID
and N.neighborType = dbo.fPhotoType('Star') -- and S2 is a star
and N.distance < .05 -- the 3 arcsecond test
and ((S1.u - S1.g) < 0.4 ) -- and S1 meets Paul Szkodys color cut for
and (S1.g - S1.r) < 0.7 -- white dwarfs.
and (S1.r - S1.i) > 0.4
and (S1.i - S1.z) > 0.4
</textarea><textarea style="display:none" id="q_686166294">-- Find quasars with a broad absorption line and a nearby galaxy.
-- within 10 arcseconds.
-- Return both the quasars and the galaxies.
--
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT Q.BestObjID as Quasar_candidate_ID , G.ObjID as Galaxy_ID, N.distance
FROM SpecObj as Q, -- Q is the specObj of the quasar candidate
Neighbors as N, -- N is the Neighbors list of Q
Galaxy as G, -- G is the nearby galaxy
SpecClass as SC, -- Spec Class
SpecLine as L, -- L is the broad line we are looking for
SpecLineNames as LN -- Line Name
WHERE Q.SpecClass =SC.value -- Q is a QSO
and SC.name in ('QSO', 'HIZ_QSO') -- Spectrum says "QSO"
and Q.SpecObjID = L.SpecObjID -- L is a spectral line of Q.
and L.LineID = LN.value -- line found and
and LN.Name != 'UNKNOWN' -- not not identified
and L.ew < -10 -- but its a prominent absorption line
and Q.BestObjID = N.ObjID -- N is a neighbor record
and G.ObjID = N.NeighborObjID -- G is a neighbor of Q
and N.distance < 10.0/60 -- and it is within 10 arcseconds of the Q.
</textarea><textarea style="display:none" id="q_2089021461">-- Find galaxies without saturated pixels within 1' of a given point.
-- ra=185.0, dec=-0.5. This query uses a function fGetNearbyObjEq,
-- which takes 3 arguments (ra,dec, distance in arcmin); this function uses
-- the Neighbors table. The Neighbors table and the Galaxy table have in
-- common the objID, so we have to select objects from both where the objIDs
-- are the same. The output of the function is a table with the Galaxy Object
-- ID and distance in arcmin from the input. This query introduces the use of
-- a JOIN to combine table contents. Also, we use the 'orDER BY' syntax,
-- which will sort the output.
SELECT TOP 100 G.objID, GN.distance
FROM Galaxy as G
JOIN dbo.fGetNearbyObjEq(185.,-0.5, 1) as GN -- this function outputs a table, so we have to do a join
on G.objID = GN.objID -- get objects from temporary neighbors table GN with desired ObjID
WHERE (G.flags & dbo.fPhotoFlags('saturated')) = 0 -- and the object is not saturated. f.PhotoFlags is a function that interprets the flag bits.
ORDER BY distance -- sort these by distance
</textarea><textarea style="display:none" id="q_535089494">-- Ellipticals with odd lines.
-- Find all elliptical galaxies with spectra that have an anomalous
-- emission line. This query introduces the SQL syntax DISTINCT, which will
-- return only one instance of the requested parameter (ObjID, in this case),
-- because our query may return the same object more than once. This is also
-- the first nested query, where we use one SELECT (the inner one) to get a
-- group of objects we are not interested in. The outer SELECT includes the
-- new syntax 'not in', which is used to perform the exclusion.
--
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT DISTINCT G.ObjID -- return qualifying galaxies
FROM
Galaxy as G, -- G is the galaxy
SpecObjAll as S, -- S is the spectra of galaxy G
SpecLineAll as L, -- L is a line of S
-- we must use SpecLineAll because SpecLine only has ID's lines
XCRedshift as XC -- the template cross-correlation redshift
WHERE G.ObjID = S.bestObjID -- connect galaxy to the spectrum
and S.SpecObjID = L.SpecObjID -- The line L must be in the spectrum S
and S.SpecObjID = XC.SpecObjID -- and there is a crosscorrelation redshift
and XC.tempNo = 8 -- Template('Elliptical') -- best Cross correlation template used is "elliptical"
and L.LineID = 0
and L.ew > 10 -- and the line is prominent by some definition, in this case, the equivalent width is over 10 Angstroms
and S.SpecObjID not in (
-- insist that there are no other lines
SELECT S.SpecObjID -- This is the chosen line.
FROM SpecLine as L1 -- L1 is another line...
-- by using SpecLine, we are automatically requiring that the line
-- be identified
WHERE S.SpecObjID = L1.SpecObjID -- ...for this object...
and abs(L.wave - L1.wave) <.01
-- ...at nearly the same wavelength...
)
</textarea><textarea style="display:none" id="q_1581828007">-- Search near BCG galaxies.
-- For each galaxy in the BCG data set (brightest cluster galaxy),
-- in 160<right ascension<170, -25<declination<35 count the number of
-- galaxies within 30" of it that have a photoz within 0.05
-- of that galaxy.
-- An extremely complex WHERE clause.
SELECT G.objID, count(N.NeighborObjID) as pop
FROM Galaxy as G, -- first gravitational lens candidate
Neighbors as N, -- precomputed list of neighbors
Galaxy as U, -- a neighbor galaxy of G
photoZ as Gpz, -- photoZ of G.
photoZ as Npz -- Neighbor photoZ
WHERE G.ra between 160 and 170
and G.dec between -5 and 5
and G.objID = N.objID -- connect G and U via the neighbors table
and U.objID = N.neighborObjID -- so that we know G and U are within
and N.objID < N.neighborObjID -- 30 arcseconds of one another.
and G.objID = Gpz.objID
and U.objID = Npz.objID
and abs(Gpz.Z - Npz.Z) < 0.05 -- restrict the photoZ differences
and (G.flags & (dbo.fPhotoFlags('BINNED1') + dbo.fPhotoFlags('BINNED2') + dbo.fPhotoFlags('BINNED4'))) > 0
--and it is detected from at least one of the binned images
and (G.flags & ( dbo.fPhotoFlags('BLENDED') + dbo.fPhotoFlags('NODEBLEND') + dbo.fPhotoFlags('CHILD'))) != dbo.fPhotoFlags('BLENDED')
--and, if it is blended, it is either a child or not deblended further ??
and (G.flags & (dbo.fPhotoFlags('EDGE') + dbo.fPhotoFlags('SATURATED'))) = 0
-- and it is not near a ccd edge or saturated, where measurements may be bad
-- and apply color cut for a BCG courtesy of James Annis of Fermilab
and G.petroMag_i > 17.5
and (G.petroMag_r > 15.5 or G.petror50_r > 2)
and (G.petroMag_r < 30 and G.g < 30 and G.r < 30 and G.i < 30)
and (G.r < 19.2
and ( 1=1 or -- huh?
(G.r < (13.1 + (7/3)*(G.g - G.r) +
-- deRed_r < 13.1 + 0.7 / 0.3 * deRed_gr
4 *(G.r - G.i - 0.18 ))
-- 1.2 / 0.3 * deRed_ri
and (( G.r - G.i - (G.g - G.r)/4 - 0.18) BETWEEN -0.2 and 0.2 )
and ((G.r +
-- petSB - deRed_r + 2.5 log10(2Pi*petror50^2)
2.5 * LOG( 2 * 3.1415 * G.petror50_r * G.petror50_r )) < 24.2 )
)
or
( (G.r < 19.5 )
and (( G.r - G.i -(G.g - G.r)/4 -.18) >
-- - deRed_gr/4 - 0.18
-- cperp = deRed_ri
(0.45 - 4*( G.g - G.r)))
-- 0.45 - deRed_gr/0.25
and ((G.g - G.r) > ( 1.35 + 0.25 *(G.r - G.i)))
and ((G.r +
-- petSB - deRed_r + 2.5 log10(2Pi*petror50^2)
2.5 * LOG( 2 * 3.1415 * G.petror50_r * G.petror50_r )) < 23.3 )
)) )
group by G.objID
</textarea><textarea style="display:none" id="q_1954768468">-- Broadest line of each spectrum with its ID.
-- (or more generally, all the columns for
-- the spectral line with the highest/lowest something)? The line width is
-- stored in the column sigma, the identification is in the column restwave.
-- (Sebastian Jester )
--
--This Sample Query will not work for SDSS3 DR8 contexts
SELECT
L.specObjId,
L.specLineID,
sMax.Maxwidth -- get the spectroscopic object ID, the line ID, and the width
FROM specLine L,
(SELECT specObjID,
Max(waveMax-waveMin) as MaxWidth
-- Define MaxWidth as the largest difference in the min and max wavelength of
-- an identified line, using the built-in Max function of SQL
FROM SpecLine
GROUP BY specObjID) as sMax
-- sMax contains a single specObjID and MaxWidth. Remember that for each line
-- identified in a given object's spectrum, there is an entry in
-- SpecLine. This means that each specObjID appears many times in SpecLine,
-- once for each line found, and they must be aggregated before performing any
-- operation such as Max. The GROUP BY is thus NECESSARY.
-- The upper FROM clause is telling us we will use the table SpecLine and this
-- new output called sMax, which contains one entry with the SpecObjID and
-- MaxWidth. If we used some other function instead of 'Max', such as 'top
-- 10', sMax would have more than row.
WHERE
L.specObjID = sMax.specObjID
and (L.waveMax-L.waveMin) = sMax.MaxWidth
-- Just as with the specObjID, each specLineID appears many times in specLine.
-- This final WHERE clause makes sure we get the one specLineID from SpecObj
-- which matches the unique combination of specObjID and MaxWidth in sMax.
</textarea><textarea style="display:none" id="q_1311402765">-- Gridded galaxy counts and masks. Actually consists of TWO queries:
-- 1) Create a gridded count of galaxies with u-g > 1 and r < 21.5 over -1 < dec < 1,
-- and 179 < R.A. < 181, on a grid, and create a map of masks over the same grid.
-- Scan the table for galaxies and group them in cells 2 arc-minuteson a side. Provide
-- predicates for the color restrictions on u-g and r and to limit the search to the
-- portion of the sky defined by the right ascension and declination conditions. Return
-- the count of qualifying galaxies in each cell.
-- 2) Run another query with the same grouping, but with a predicate to include only
-- objects such as satellites, planets, and airplanes that obscure the cell. The second
-- query returns a list of cell coordinates that serve as a mask for the first query.
--- First find the gridded galaxy count (with the color cut)
--- In local tangent plane, ra/cos(dec) is a linear degree.
SELECT cast((ra/cos(cast(dec*30 as int)/30.0))*30 as int)/30.0 as raCosDec,
cast(dec*30 as int)/30.0 as dec,
count(*) as pop
FROM Galaxy as G
JOIN dbo.fHTMCoverRegion('CHULL J2000 179 -1 179 1 181 1 181 -1') AS T
ON G.htmID BETWEEN T.HTMIDstart AND T. HTMIDend
WHERE ra between 179 and 181
and dec between -1 and 1
and u-g > 1
and r < 21.5
GROUP BY cast((ra/cos(cast(dec*30 as int)/30.0))*30 as int)/30.0,
cast(dec*30 as int)/30.0
-- now build mask grid.
-- This is a separate query if no temp tables can be made
SELECT cast((ra/cos(cast(dec*30 as int)/30.0))*30 as int)/30.0 as raCosDec,
cast(dec*30 as int)/30.0 as dec,
count(*) as pop
FROM PhotoObj as PO
JOIN dbo.fHTMCoverRegion('CHULL J2000 179 -1 179 1 181 1 181 -1') AS T
ON PO.htmID BETWEEN T.HTMIDstart AND T.HTMIDend
JOIN PhotoType as PT ON PO.type = PT.value
WHERE
ra between 179 and 181
and dec between -1 and 1
and PT.name in ('COSMIC_RAY', 'DEFECT', 'GHOST', 'TRAIL', 'UNKNOWN')
GROUP BY cast((ra/cos(cast(dec*30 as int)/30.0))*30 as int)/30.0,
cast(dec*30 as int)/30.0 </textarea><textarea style="display:none" id="q_1594656083">-- Create a count of galaxies for each of the HTM triangles.
-- Galaxies should satisfy a certain color cut,
-- like 0.7u-0.5g-0.2i<1.25 && r<21.75, output it in a form
-- adequate for visualization.
SELECT (htmID / power(2,24)) as htm_8 ,
-- group by 8-deep HTMID (rshift HTM by 12)
avg(ra) as ra,
avg(dec) as [dec],
count(*) as pop -- return center point and count for display
FROM Galaxy -- only look at galaxies
WHERE (0.7*u - 0.5*g - 0.2*i) < 1.25 -- meeting this color cut
and r < 21.75 -- brighter than 21.75 magnitude in red band.
group by (htmID /power(2,24)) -- group into 8-deep HTM buckets.
</textarea><textarea style="display:none" id="q_1399733903">-- Find stars with multiple measurements with magnitude variations >0.1.
-- Note that this runs very slowly unless explicit workarounds are included
-- for some SQLServer Optimizer bugs, which are NOT included here
SELECT TOP 100
S1.objID as objID1, S2.objID as ObjID2 -- select object IDs of star and its pair
FROM Star as S1, -- the primary star
photoObj as S2, -- the second observation of the star
neighbors as N -- the neighbor record
WHERE S1.objID = N.objID -- insist the stars are neighbors
and S2.objID = N.neighborObjID -- using precomputed neighbors table
and distance < 0.5/60 -- distance is 0.5 arc second or less
and S1.run != S2.run -- observations are two different runs
and S2.type = dbo.fPhotoType('Star') -- S2 is indeed a star
and S1.u between 1 and 27 -- S1 magnitudes are reasonable
and S1.g between 1 and 27
and S1.r between 1 and 27
and S1.i between 1 and 27
and S1.z between 1 and 27
and S2.u between 1 and 27 -- S2 magnitudes are reasonable.
and S2.g between 1 and 27
and S2.r between 1 and 27
and S2.i between 1 and 27
and S2.z between 1 and 27
and ( -- and one of the colors is different.
abs(S1.u-S2.u) > .1 + (abs(S1.Err_u) + abs(S2.Err_u))
or abs(S1.g-S2.g) > .1 + (abs(S1.Err_g) + abs(S2.Err_g))
or abs(S1.r-S2.r) > .1 + (abs(S1.Err_r) + abs(S2.Err_r))
or abs(S1.i-S2.i) > .1 + (abs(S1.Err_i) + abs(S2.Err_i))
or abs(S1.z-S2.z) > .1 + (abs(S1.Err_z) + abs(S2.Err_z))
)
</textarea><textarea style="display:none" id="q_532479277">-- This query uses the new SQL Server 2005 CROSS APPLY and OUTER APPLY
-- constructs to apply a table-valued function to the results of a query.
-- In this example, we use the fFootPrintEq function which returns a list
-- of SDSS regions that intersect the area specified by the RA, dec and
-- radius, or NULL if the area is outside the SDSS footprint.
-- For each point in the input list, in this case the result of a query
-- on PhotoObj, return "yes" or "no" depending on whether the point is in
-- the SDSS footprint or not, and any other needed columns.
SELECT top 100 objID, ra, dec,
(case when p.type is null then 'NO' else 'YES' end) as found
FROM PhotoObj AS p
OUTER APPLY dbo.fFootprintEq(ra,dec,0.1)
WHERE (ra between 179.5 and 182.3) and (dec between -1.0 and 1.8)
</textarea>
<textarea style="display:none" id="q_1774811490">-- Find unique objects in an RA/Dec box.
-- PhotoPrimary is a view which selects only unique objects.
-- The full list of good detections including duplicates is in PhotoObj
-- A basic SELECT-FROM-WHERE query.
SELECT TOP 100 objID, -- Get the unique object ID,
field, ra, dec -- the field number, and coordinates
FROM PhotoPrimary -- From the photometric data
WHERE
ra > 185. and ra < 185.1 and dec > 15. and dec < 15.1 </textarea><textarea style="display:none" id="q_1950906038">-- Galaxies meeting two simple criteria.
-- Find all galaxies brighter than r magnitude 22, where the local
-- extinction is > 0.175. This is a simple query that uses a WHERE clause,
-- but now two conditions that must be met simultaneously.
SELECT TOP 10 objID
FROM Galaxy
WHERE
r < 22 -- r IS NOT deredenned
and extinction_r > 0.175 -- extinction more than 0.175
</textarea><textarea style="display:none" id="q_118442681">-- Find specific types of quasars using spectroscopy.
-- The easiest way to find quasars is by finding objects whose spectra have
-- been classified as quasars. This sample query searches the SpecObj
-- table for the IDs and redshifts of objects with the class column equal to 'QSO'
SELECT TOP 100 specObjID, z
FROM SpecObj
WHERE class = 'QSO' AND zWarning = 0
</textarea><textarea style="display:none" id="q_1087655456">-- Using the BETWEEN syntax.
-- Find all galaxies in a certain area of the sky that also meet other
-- criteria in their measured parameters. This query intriduces the
-- BETWEEN construct to specify a range of values.
SELECT TOP 100 objID, ra, dec, cModelMag_g
FROM Galaxy
WHERE ra BETWEEN 178 AND 180
AND dec < 0
AND cModelMag_g BETWEEN 18 AND 19
</textarea><textarea style="display:none" id="q_1315557362">-- Using spatial unit vectors for coordinate cuts.
-- Find galaxies in a given area of the sky, using a coordinate cut
-- in the unit vector cx,cy,cz that corresponds to a specific RA range.
-- Another simple query that uses math in the WHERE clause.
--
-- NOTE: This query must be run in batch mode, i.e. using the Submit button
-- because it takes too long to execute in Quick mode.
SELECT TOP 100 colc_g, colc_r
FROM Galaxy
WHERE
(-0.466 * cx + 0.689 * cy>=0)
and (-0.385 * cx - 0.173 * cy <0)
</textarea><textarea style="display:none" id="q_671661625">-- Find CVs using colors.
-- Search for Cataclysmic Variables and pre-CVs with White Dwarfs and
-- very late secondaries. Just uses some simple color cuts from Paula Szkody.
-- Another simple query that uses math in the WHERE clause
SELECT TOP 100 run,
camCol,
rerun,
field,
objID,
u, g, r, i, z,
ra, dec -- Just get some basic quantities
FROM PhotoPrimary -- From all primary detections, regardless of class
WHERE u - g < 0.4
and g - r < 0.7
and r - i > 0.4
and i - z > 0.4 -- that meet the color criteria
</textarea><textarea style="display:none" id="q_474354453">-- Getting a subsample of the data.
--
-- Uses the integer short object id (obj) - which is the least significant bits
-- of the long objID - and the '%' operator (remainder) to get every 1000th
-- object.
-- NOTE: THIS IS NOT A TRULY RANDOM SAMPLE!
SELECT TOP 100 u, g, r, i, z
FROM Galaxy with (nolock)
WHERE (objID%1000) = 1
AND (r between 18 and 21)
</textarea><textarea style="display:none" id="q_765492618">-- Low-z QSO candidates using color cuts.
-- from Gordon Richards.
-- Also a simple query with a long WHERE clause.
SELECT TOP 1000 g, run, rerun, camcol, field, objID
FROM
Galaxy
WHERE (
(g <= 22) and
(u-g >= -0.27) and (u-g < 0.71) and
(g-r >= -0.24) and (g-r < 0.35) and
(r-i >= -0.27) and (r-i < 0.57) and
(i-z >= -0.35) and (i-z < 0.70)
)</textarea><textarea style="display:none" id="q_453245167">-- Get object velocities and errors.
-- This is also a simple query that uses a WHERE clause.
-- However, now we perform a more complex mathematical operation.
SELECT TOP 10
run, -- get a bunch of quantities
camCol,
field,
objID,
rowC, colC, rowV, colV, rowVErr, colVErr,
flags,
psfMag_u, psfMag_g, psfMag_r, psfMag_i, psfMag_z,
psfMagErr_u, psfMagErr_g, psfMagErr_r, psfMagErr_i, psfMagErr_z
FROM PhotoPrimary
WHERE ((rowv * rowv) / (rowvErr * rowvErr) +
(colv * colv) / (colvErr * colvErr) > 4)
-- where the velocities are reliable
</textarea><textarea style="display:none" id="q_1745962591">-- Finding galaxies by their emission lines:
--
-- SDSS-III handles searches by spectral lines differently than previous
-- releases. In addition, spectral lines for galaxies and stars are
-- identified through different processes. See the "Spectra of Red
-- Stars" sample query for an example of using stellar spectra.
--
-- Spectral lines for galaxies are calculated using the MPA-JHU
-- spectroscopic reanalysis (Tremonti et al. 2004; Brinchmann et al. 2004)
-- and are stored in the galSpecLine table. For more on how spectral lines
-- of galaxies are found, see the Galspec page of the sdss3.org website.
--
-- This query selects galaxy spectra with high internal reddening,
-- as measured by the standard Balmer decrement technique. It
-- makes use of the galSpec tables for the measurements of
-- galaxy lines. In this case we use galSpecLine, which has
-- emission line measurements.
SELECT
s.plate, s.fiberid, s.mjd, s.z, s.zwarning,
g.h_beta_flux, g.h_beta_flux_err,
g.h_alpha_flux, g.h_alpha_flux_err
FROM GalSpecLine AS g
JOIN dbo.SpecObj AS s ON s.specobjid = g.specobjid
WHERE
h_alpha_flux > h_alpha_flux_err*5
AND h_beta_flux > h_beta_flux_err*5
AND h_beta_flux_err > 0
AND h_alpha_flux > 10.*h_beta_flux
AND s.class = 'GALAXY'
AND s.zwarning = 0
</textarea><textarea style="display:none" id="q_23566870">-- Moving objects consistent with an asteroid.
-- Also a simple query, but we introduce the 'as' syntax, which allows us to
-- name derived quantities in the result file.
--
-- NOTE: Since asteroids are rare objects in the SDSS data, this query will
-- take a long time to run without the "TOP 10" and should be executed
-- in batch mode (with the Submit button).
SELECT TOP 10
objID,
sqrt( power(rowv,2) + power(colv, 2) ) as velocity
FROM PhotoObj
WHERE
(power(rowv,2) + power(colv, 2)) between 50 and 1000
</textarea><textarea style="display:none" id="q_225105383">-- Find quasars in imaging data.
-- as specified by Xiaohui Fan et.al.
-- A rather straightforward query, just with many conditions.
SELECT TOP 100 run,
camCol,
rerun,
field,
objID,
u, g, r, i, z,
ra, dec
FROM Star -- or Galaxy
WHERE ( u - g > 2.0 or u > 22.3 )
and ( i < 19 )
and ( i > 0 )
and ( g - r > 1.0 )
and ( r - i <
(0.08 + 0.42 * (g - r - 0.96) )
or g - r > 2.26 )
and ( i - z < 0.25 )
</textarea><textarea style="display:none" id="q_834528110">-- Using object counting and logic in a query.
-- Find all objects similar to the colors of a quasar at 5.5<redshift<6.5.
-- An area restriction is added so the query will run in the Quick queue.
SELECT count(*) as 'total',
sum( case when (Type=3) then 1 else 0 end) as 'Galaxies',
sum( case when (Type=6) then 1 else 0 end) as 'Stars',
sum( case when (Type not in (3,6)) then 1 else 0 end) as 'Other'
FROM PhotoPrimary -- for each object
WHERE
(ra between 180 and 190) and (dec between -5 and 5)
and (( u - g > 2.0) or (u > 22.3) ) -- apply the quasar color cut.
and ( i between 0 and 19 )
and ( g - r > 1.0 )
and ( (r - i < 0.08 + 0.42 * (g - r - 0.96)) or (g - r > 2.26 ) )
and ( i - z < 0.25 )
</textarea><textarea style="display:none" id="q_245836436">-- Find galaxies that are blended with a star.
-- Output the deblended galaxy magnitudes.
-- This query introduces the use of multiple tables or views. You can assign
-- nicknames to tables as in the FROM clause below. Since you are using
-- multiple tables, you must specify which table each quantity in the SELECT
-- clause comes from. The query illustrates the JOIN syntax between
-- the two tables, which requires that a common quantity that is present in
-- both tables be equal, in this case their common parent object.
SELECT top 1000 G.ObjID, G.u, G.g, G.r, G.i, G.z
FROM Galaxy G -- compare Galaxy and Star
JOIN Star S ON G.parentID = S.parentID -- using the same parent
WHERE
G.parentID > 0 -- if the galaxy has a "parent", this object was deblended
</textarea><textarea style="display:none" id="q_1952789469">-- Stars selected using Field criteria.
-- Give me the PSF colors of all stars brighter than g=20 that have PSP_STATUS = 2.
-- Another simple multi-table query.
SELECT TOP 1000
s.psfMag_g, -- or whatever you want from each object
s.run,
s.camCol,
s.rerun,
s.field
FROM Star s
JOIN Field f ON s.fieldID = f.fieldID
WHERE
s.psfMag_g < 20
and f.pspStatus = 2
</textarea><textarea style="display:none" id="q_1577813389">-- Objects selected by cuts on three tables.
-- Find the parameters for all objects in a selected field with
-- desired PSF width and range of columns.
-- Now we are using three tables, but it is still a simple query.
SELECT TOP 1000
f.run,
f.rerun,
f.camCol,
f.field,
p.objID,
p.ra,
p.dec,
p.Rowc,
p.Colc,
p.u,
p.modelMagErr_u ,
p.g,
p.modelMagErr_g,
p.r,
p.modelMagErr_r,
p.petroMag_r - p.extinction_r,
p.petroMagErr_r,
p.i,
p.modelMagErr_i,
p.z,
f.psfWidth_r,
r.stripe,
r.strip
FROM
photoObj p
JOIN field f ON f.fieldid = p.fieldid
JOIN run r ON r.run=f.run
WHERE
f.psfWidth_r > 1.2
and p.colc > 400.0
</textarea><textarea style="display:none" id="q_1362554404">-- Find all objects within 30 arcseconds of one another
-- that have very similar colors: that is where the color ratios
-- u-g, g-r, r-I are less than 0.05m. This query introduces the
-- Neighbors table, which is a pre-computed list of the nearest
-- neighbors of each object within 30 arcseconds.
SELECT TOP 10 P.ObjID as objid1, L.ObjID as objid2, N.distance
FROM PhotoPrimary P -- P is the primary object
JOIN Neighbors N ON P.ObjID = N.ObjID -- N is the neighbor link
JOIN PhotoPrimary L ON L.ObjID = N.NeighborObjID -- L is the lens candidate of P
WHERE
P.ObjID < L. ObjID -- avoid duplicates
and abs((P.u-P.g)-(L.u-L.g))<0.05 -- L and P have similar spectra
and abs((P.g-P.r)-(L.g-L.r))<0.05
and abs((P.r-P.i)-(L.r-L.i))<0.05
and abs((P.i-P.z)-(L.i-L.z))<0.05
</textarea><textarea style="display:none" id="q_1335992021">-- Find stars with multiple measurements with magnitude variations >0.1.
-- Note that this runs very slowly unless explicit workarounds are included
-- for some SQLServer Optimizer bugs, which are NOT included here
SELECT TOP 100
S1.objID as objID1, S2.objID as ObjID2 -- select object IDs of star and its pair
FROM Star as S1, -- the primary star
photoObj as S2, -- the second observation of the star
neighbors as N -- the neighbor record
WHERE S1.objID = N.objID -- insist the stars are neighbors
and S2.objID = N.neighborObjID -- using precomputed neighbors table
and distance < 0.5/60 -- distance is 0.5 arc second or less
and S1.run != S2.run -- observations are two different runs
and S2.type = dbo.fPhotoType('Star') -- S2 is indeed a star
and S1.u between 1 and 27 -- S1 magnitudes are reasonable
and S1.g between 1 and 27
and S1.r between 1 and 27
and S1.i between 1 and 27
and S1.z between 1 and 27
and S2.u between 1 and 27 -- S2 magnitudes are reasonable.
and S2.g between 1 and 27
and S2.r between 1 and 27
and S2.i between 1 and 27
and S2.z between 1 and 27
and ( -- and one of the colors is different.
abs(S1.u-S2.u) > .1 + (abs(S1.Err_u) + abs(S2.Err_u))
or abs(S1.g-S2.g) > .1 + (abs(S1.Err_g) + abs(S2.Err_g))
or abs(S1.r-S2.r) > .1 + (abs(S1.Err_r) + abs(S2.Err_r))
or abs(S1.i-S2.i) > .1 + (abs(S1.Err_i) + abs(S2.Err_i))
or abs(S1.z-S2.z) > .1 + (abs(S1.Err_z) + abs(S2.Err_z))
)
</textarea><textarea style="display:none" id="q_999622185">-- Checking for errors using flags.
-- Another useful query is to see if the errors on moving (or
-- apparently moving) objects are correct. For example, it used to be that
-- some known QSOs were being flagged as moving objects. One way to look for
-- such objects is to compare the velocity to the error in velocity and see if
-- the "OBJECT1_MOVED" or "OBJECT2_BAD_MOVING_FIT" is set.
-- This query introduces bitwise logic for flags, and uses the 'as' syntax to
-- make the query more readable. Note that if a flag is not set, the value
-- will be zero. If you want to ensure multiple flags are not set, you can
-- either check that each individually is zero, or that their sum is zero.
-- (From Gordon Richards)
--
-- NOTE: A caveat about using functons (like fPhotoFlags) is that if your
-- query is selecting a very large number of rows (e.g. hundreds of
-- thousands or millions) then it's that many function calls, and
-- this will slow down the query execution significantly. In that
-- case, you should replace the function call with its equivalent
-- binary bitmask, e.g. if you run the query (with Quick button)
-- SELECT (dbo.fPhotoFlags('MOVED') + dbo.fPhotoFlags('BAD_MOVING_FIT'))
-- you will get the value 36507222016, which you can substitute in
-- first line of the WHERE clause below as:
-- (flags & 36507222016) > 0
-- to avoid zillions of function calls.
SELECT TOP 1000
run,
rerun,
camcol,
field,
objID,
ra, dec,
rowv, colv,
rowvErr, colvErr,
i,
(flags & dbo.fPhotoFlags('MOVED')) as MOVED,
(flags & dbo.fPhotoFlags('BAD_MOVING_FIT')) as BAD_MOVING_FIT
FROM Galaxy
WHERE
(flags & (dbo.fPhotoFlags('MOVED') + dbo.fPhotoFlags('BAD_MOVING_FIT'))) > 0
and (rowv * rowv + colv * colv) >=
(rowvErr * rowvErr + colvErr * colvErr)
</textarea><textarea style="display:none" id="q_416441924">-- Elliptical galaxies based on model fits.
-- Find all galaxies with a deVaucouleours profile and the
-- photometric colors consistent with an elliptical galaxy.
-- This query has many conditions, and also shows more of the
-- bitwise logic necessary for dealing with flags.
SELECT TOP 100 ObjID
FROM Galaxy as G
WHERE
G.lnlDev_r > G.lnlExp_r + 0.1
-- the likelihood of the deVaucouleours profile fit is 10% greater than the likelihood of the exponential fit
and G.lnlExp_r > -999
-- and the likelihoods are actually meaningful
and (G.flags & (dbo.fPhotoFlags('BINNED1') + dbo.fPhotoFlags('BINNED2') + dbo.fPhotoFlags('BINNED4'))) > 0
--and it is detected from at least one of the binned images ???
and (G.flags & ( dbo.fPhotoFlags('BLENDED') + dbo.fPhotoFlags('NODEBLEND') + dbo.fPhotoFlags('CHILD'))) != dbo.fPhotoFlags('BLENDED')
--and, if it is blended, it is either a child or not deblended further ??
and (G.flags & (dbo.fPhotoFlags('EDGE') + dbo.fPhotoFlags('SATURATED'))) = 0
-- and it is not near a ccd edge or saturated, where measurements may be bad
and G.petroMag_i > 17.5
-- and it is fainter than 17.5 in i-band
and (G.petroMag_r > 15.5 or G.petror50_r > 2)
and (G.petroMag_r > 0 and G.g > 0 and G.r > 0 and G.i > 0)
and ( (G.petroMag_r - G.extinction_r) < 19.2
and (G.petroMag_r - G.extinction_r <
(13.1 + (7/3)*(G.g - G.r) + 4 *(G.r - G.i) - 4 * 0.18 ) )
and ( (G.r - G.i - (G.g - G.r)/4 - 0.18) < 0.2 )
and ( (G.r - G.i - (G.g - G.r)/4 - 0.18) > -0.2 ) )
or ( (G.petroMag_r - G.extinction_r < 19.5)
and ( (G.r - G.i - (G.g - G.r)/4 - 0.18) >
(0.45 - 4*(G.g - G.r) ) )
and ( (G.g - G.r) > (1.35 + 0.25 *(G.r - G.i) ) ) )
-- and many constraints on colors and mags are met to make it have
-- elliptical-type colors.
</textarea><textarea style="display:none" id="q_2043177420">-- Galaxies with bluer centers.
-- by Michael Strauss. For all galaxies
-- with r_Petro < 18, not saturated, not bright, and not edge, give me those
-- with centers appreciably bluer than their outer parts, i.e., define the
-- center color as: u_psf - g_psf and define the outer color as: u_model -
-- g_model; give me all objs which have (u_model - g_model) - (u_psf - g_psf)
-- < -0.4
-- Another flags-based query.
SELECT TOP 1000
colc_u, colc_g, objID
FROM Galaxy
WHERE
( Flags & (dbo.fPhotoFlags('SATURATED') +
dbo.fPhotoFlags('BRIGHT') +
dbo.fPhotoFlags('EDGE')) ) = 0
and petrorad_r < 18
and ((colc_u - colc_g) - (psfMag_u - psfMag_g)) < -0.4</textarea><textarea style="display:none" id="q_538360056">-- Diameter-limited sample of galaxies
-- from James Annis.
-- Another query that makes extensive use of photo flags to get a sample
-- of galaxies within a size range as specified by their i-band Petrosian
-- radius.
SELECT TOP 100
run,
camCol,
rerun,
field,
objID,
ra,
dec
FROM Galaxy
WHERE ( flags & (dbo.fPhotoFlags('BINNED1')
+ dbo.fPhotoFlags('BINNED2')
+ dbo.fPhotoFlags('BINNED4')) ) > 0
and ( flags & (dbo.fPhotoFlags('BLENDED')
+ dbo.fPhotoFlags('NODEBLEND')
+ dbo.fPhotoFlags('CHILD')) ) != dbo.fPhotoFlags('BLENDED')
and ( ( (flags & dbo.fPhotoFlags('NOPETRO') = 0)
and petrorad_i > 15)
or ( (flags & dbo.fPhotoFlags('NOPETRO') > 0)
and petrorad_i > 7.5)
or ( (flags & dbo.fPhotoFlags('TOO_LARGE') > 0)
and petrorad_i > 2.5)
or
( (flags & dbo.fPhotoFlags('SATURATED') = 0)
and petrorad_i > 17.5) )
</textarea><textarea style="display:none" id="q_1596667058">-- Extremely red galaxies.
-- from James Annis.
-- Similar to the diameter limited sample query but selects galaxies that
-- are red (i-z color greater than a certain threshold).
SELECT TOP 1000
g.run,
g.camCol,
g.rerun,
g.field,
g.objID,
g.ra, g.dec
FROM Field f, Galaxy g
WHERE
g.fieldID = f.fieldID
and ( g.flags & (dbo.fPhotoFlags('BINNED1')
+ dbo.fPhotoFlags('BINNED2')
+ dbo.fPhotoFlags('BINNED4')) ) > 0
and ( g.flags & (dbo.fPhotoFlags('BLENDED')
+ dbo.fPhotoFlags('NODEBLEND')
+ dbo.fPhotoFlags('CHILD')) ) != dbo.fPhotoFlags('BLENDED')
and ( g.flags & (dbo.fPhotoFlags('COSMIC_RAY')
+ dbo.fPhotoFlags('INTERP')) ) = 0
and f.psfWidth_r < 1.5
and (g.i - g.z > 1.0 )
</textarea><textarea style="display:none" id="q_1317231909">-- A version of the LRG sample.
-- by James Annis.
-- Another query with many conditions and flag tests that selects Luminous
-- Red Galaxies (LRGs).
SELECT TOP 100
run,
camCol,
rerun,
field,
objID,
ra,
dec
FROM Galaxy
WHERE ( ( flags & (dbo.fPhotoFlags('BINNED1')
+ dbo.fPhotoFlags('BINNED2')
+ dbo.fPhotoFlags('BINNED4')) ) > 0
and ( flags & (dbo.fPhotoFlags('BLENDED')
+ dbo.fPhotoFlags('NODEBLEND')
+ dbo.fPhotoFlags('CHILD')) ) != dbo.fPhotoFlags('BLENDED')
and ( flags & (dbo.fPhotoFlags('EDGE')
+ dbo.fPhotoFlags('SATURATED')) ) = 0
and petroMag_i > 17.5
and (petroMag_r > 15.5 or petror50_r > 2)
and (petroMag_r > 0 and g > 0 and r > 0 and i > 0)
and ( (petroMag_r-extinction_r) < 19.2
and (petroMag_r - extinction_r <
(13.1 + (7/3) * (dered_g - dered_r) + 4 * (dered_r - dered_i) - 4 * 0.18) )
and ( (dered_r - dered_i - (dered_g - dered_r)/4 - 0.18) < 0.2)
and ( (dered_r - dered_i - (dered_g - dered_r)/4 - 0.18) > -0.2)
--dered_ quantities already include extinction
and ( (petroMag_r - extinction_r +
2.5 * LOG10(2 * 3.1415 * petror50_r * petror50_r)) < 24.2) )
or ( (petroMag_r - extinction_r < 19.5)
and ( (dered_r - dered_i - (dered_g - dered_r)/4 - 0.18) > (0.45 - 4 * (dered_g - dered_r)) )
and ( (dered_g - dered_r) > (1.35 + 0.25 * (dered_r - dered_i)) ) )
and ( (petroMag_r - extinction_r +
2.5 * LOG10(2 * 3.1415 * petror50_r * petror50_r) ) < 23.3 ) )
</textarea><textarea style="display:none" id="q_1838668250">-- Spectra of Red Stars
--
-- SDSS-III handles searches by spectral lines differently than previous
-- releases. In addition, spectral lines for galaxies and stars are
-- identified through different processes. See the "Galaxies with
-- Emission Lines" sample query for an example of using galaxy spectra.
--
-- Spectral lines for stars are calculated using the SEGUE Stellar Parameter
-- Pipeline (SSPP; Lee et al. 2008) and are stored in the sppLines
-- table. For more on how spectral lines of stars are found, see
-- the SSPP page of the sdss3.org website.
-- This query selects red stars (spectral type K), with large
-- CaII triplet eq widths, with low errors on the CaII triplet
-- equivalent widths.
SELECT
sl.plate,sl.mjd,sl.fiber,
sl.caIIKside,sl.caIIKerr,sl.caIIKmask,
sp.fehadop,sp.fehadopunc,sp.fehadopn,
sp.loggadopn,sp.loggadopunc
FROM sppLines AS sl
JOIN sppParams AS sp ON sl.specobjid = sp.specobjid
WHERE
fehadop < -3.5
AND fehadopunc between 0.01
and 0.5 and fehadopn > 3
</textarea><textarea style="display:none" id="q_2014769771">-- Galaxy counts on HTM grid.
--
-- Create a count of galaxies for each of the Hierarchical Triangular Mesh (HTM) triangles.
-- Galaxies should satisfy a certain color cut like 0.7u-0.5g-0.2i<1.25 && r<21.75, output
-- it in a form adequate for visualization.
SELECT (htmID / power(2,24)) as htm_8 ,
-- group by 8-deep HTMID (rshift HTM by 12)
avg(ra) as ra,
avg(dec) as [dec],
count(*) as pop -- return center point and count for display
FROM Galaxy -- only look at galaxies
WHERE
-- RA/dec cut added to make query run in Quick mode
(ra between 180 and 181 and dec between -1 and 1) and
(0.7*u - 0.5*g - 0.2*i) < 1.25 -- meeting this color cut
and r < 21.75 -- brighter than 21.75 magnitude in red band.
group by (htmID /power(2,24)) -- group into 8-deep HTM buckets.
</textarea><textarea style="display:none" id="q_1687012106">-- Binary Stars Colors.
--
-- Find binary stars with specific colors.
-- At least one of them should have the colors (meets Paul Szkody's color cut) of a white dwarf.
SELECT TOP 100 s1.objID as s1, s2.objID as s2
FROM Star S1 -- S1 is the white dwarf
JOIN Neighbors N ON S1.objID = N. objID -- N is the precomputed neighbors link
JOIN Star S2 ON S2.objID = N.NeighborObjID -- S2 is the second star
WHERE
N.neighborType = dbo.fPhotoType('Star') -- and S2 is a star
and N.distance < .05 -- the 3 arcsecond test
and ((S1.u - S1.g) < 0.4 ) -- and S1 meets the color cut for
and (S1.g - S1.r) < 0.7 -- white dwarfs.
and (S1.r - S1.i) > 0.4
and (S1.i - S1.z) > 0.4
</textarea><textarea style="display:none" id="q_1632881509">-- Galaxies unsaturated near (given) coordinates.
--
-- Find galaxies without saturated pixels within 1' of a given point.
-- ra=185.0, dec=-0.5. This query uses a function fGetNearbyObjEq,
-- which takes 3 arguments (ra,dec, distance in arcmin); this function uses
-- the Neighbors table. The Neighbors table and the Galaxy table have in
-- common the objID, so we have to select objects from both where the objIDs
-- are the same. The output of the function is a table with the Galaxy Object
-- ID and distance in arcmin from the input. This query introduces the use of
-- a JOIN to combine table contents. Also, we use the 'ORDER BY' syntax,
-- which will sort the output.
SELECT TOP 100 G.objID, GN.distance
FROM Galaxy AS G
JOIN dbo.fGetNearbyObjEq(185.,-0.5, 1) AS GN -- this function outputs a table, so we have to do a join
ON G.objID = GN.objID -- get objects from temporary neighbors table GN with desired ObjID
WHERE
(G.flags & dbo.fPhotoFlags('saturated')) = 0 -- and the object is not saturated. f.PhotoFlags is a function that interprets the flag bits.
ORDER BY distance -- sort these by distance
</textarea><textarea style="display:none" id="q_103654135">-- Search near BCG galaxies.
--
-- For each galaxy in the BCG data set (brightest cluster galaxy),
-- in 160<right ascension<170, -25<declination<35 count the number of
-- galaxies within 30" of it that have a photoz within 0.05
-- of that galaxy.
-- This query has a very complex WHERE clause.
SELECT TOP 1000 G.objID, COUNT(N.NeighborObjID) AS pop
FROM Galaxy AS G -- first gravitational lens candidate
JOIN Neighbors AS N ON G.objID = N.objID -- precomputed list of neighbors
JOIN Galaxy AS U ON U.objID = N.neighborObjID -- a neighbor galaxy of G
JOIN photoZ AS Gpz ON G.objID = Gpz.objID -- photoZ of G.
JOIN photoZ AS Npz ON U.objID = Npz.objID -- neighbor photoZ
WHERE
G.ra BETWEEN 160 AND 170
AND G.dec BETWEEN -5 AND 5
AND N.objID < N.neighborObjID -- 30 arcseconds of one another.
AND ABS(Gpz.Z - Npz.Z) < 0.05 -- restrict the photoZ differences
AND (G.flags & (dbo.fPhotoFlags('BINNED1') + dbo.fPhotoFlags('BINNED2') + dbo.fPhotoFlags('BINNED4'))) > 0
--and it is detected from at least one of the binned images
AND (G.flags & ( dbo.fPhotoFlags('BLENDED') + dbo.fPhotoFlags('NODEBLEND') + dbo.fPhotoFlags('CHILD'))) != dbo.fPhotoFlags('BLENDED')
--and, if it is blended, it is either a child or not deblended further ??
AND (G.flags & (dbo.fPhotoFlags('EDGE') + dbo.fPhotoFlags('SATURATED'))) = 0
-- and it is not near a ccd edge or saturated, where measurements may be bad
-- and apply color cut for a BCG courtesy of James Annis of Fermilab
AND G.petroMag_i > 17.5
AND (G.petroMag_r > 15.5 or G.petror50_r > 2)
AND (G.petroMag_r < 30 AND G.g < 30 AND G.r < 30 AND G.i < 30)
AND (G.r < 19.2
AND ( 1=1 or -- huh?
(G.r < (13.1 + (7/3)*(G.g - G.r) +
-- deRed_r < 13.1 + 0.7 / 0.3 * deRed_gr
4 *(G.r - G.i - 0.18 ))
-- 1.2 / 0.3 * deRed_ri
AND (( G.r - G.i - (G.g - G.r)/4 - 0.18) BETWEEN -0.2 AND 0.2 )
AND ((G.r +
-- petSB - deRed_r + 2.5 log10(2Pi*petror50^2)
2.5 * LOG( 2 * 3.1415 * G.petror50_r * G.petror50_r )) < 24.2 )
)
or
( (G.r < 19.5 )
AND (( G.r - G.i -(G.g - G.r)/4 -.18) >
-- - deRed_gr/4 - 0.18
-- cperp = deRed_ri
(0.45 - 4*( G.g - G.r)))
-- 0.45 - deRed_gr/0.25
AND ((G.g - G.r) > ( 1.35 + 0.25 *(G.r - G.i)))
AND ((G.r +
-- petSB - deRed_r + 2.5 log10(2Pi*petror50^2)
2.5 * LOG( 2 * 3.1415 * G.petror50_r * G.petror50_r )) < 23.3 )
)) )
GROUP BY G.objID
</textarea><textarea style="display:none" id="q_675428088">-- The detectionIndex table contains all detections of a given physical object,
-- which is uniquely identified by the "thingid". In order to extract photometry,
-- you need a join with the PhotoObjAll table, using the objid.
-- There is also a flag field called isPrimary, which is 1 for the object that
-- is found on a primary polygon/field, all the other detections have 0 in this field.
-- Here is a compound query to find all time series around a certain object with a thingid= 97423000
SELECT
LTRIM(STR(mjd_r,20,2)) AS MJD,
dbo.fSDSS(p.objId) AS ID,
modelMag_g, modelMagErr_g,
modelMag_r, modelMagErr_r,
modelMag_i, modelMagErr_i, p.ra, p.dec
INTO #list
FROM detectionindex d
JOIN PhotoObjAll p ON d.objid=p.objid
JOIN Field f ON p.fieldid=f.fieldid
WHERE d.thingid=97423000
ORDER BY 1
GO
--
-- Now find objects near each of the detections
--
SELECT a.*, b.*
FROM #list a
CROSS APPLY dbo.fGetNearbyObjEq(a.ra, a.dec, 0.1) b
</textarea>
<textarea style="display:none" id="q_1651054877">-- Find unique objects in an RA/Dec box.
-- PhotoPrimary is a view which selects only unique objects.
-- The full list of good detections including duplicates is in PhotoObj
-- A basic SELECT-FROM-WHERE query.
SELECT TOP 100 objID, -- Get the unique object ID,
field, ra, dec -- the field number, and coordinates
FROM PhotoPrimary -- From the photometric data
WHERE
ra > 185. and ra < 185.1 and dec > 15. and dec < 15.1 </textarea><textarea style="display:none" id="q_229416785">-- Galaxies meeting two simple criteria.
-- Find all galaxies brighter than r magnitude 22, where the local
-- extinction is > 0.175. This is a simple query that uses a WHERE clause,
-- but now two conditions that must be met simultaneously.
SELECT TOP 10 objID
FROM Galaxy
WHERE
r < 22 -- r IS NOT deredenned
and extinction_r > 0.175 -- extinction more than 0.175
</textarea><textarea style="display:none" id="q_639018260">-- Find specific types of quasars using spectroscopy.
-- The easiest way to find quasars is by finding objects whose spectra have
-- been classified as quasars. This sample query searches the SpecObj
-- table for the IDs and redshifts of objects with the class column equal to 'QSO'
SELECT TOP 100 specObjID, z
FROM SpecObj
WHERE class = 'QSO' AND zWarning = 0
</textarea><textarea style="display:none" id="q_906922939">-- Using the BETWEEN syntax.
-- Find all galaxies in a certain area of the sky that also meet other
-- criteria in their measured parameters. This query intriduces the
-- BETWEEN construct to specify a range of values.
SELECT TOP 100 objID, ra, dec, cModelMag_g
FROM Galaxy
WHERE ra BETWEEN 178 AND 180
AND dec < 0
AND cModelMag_g BETWEEN 18 AND 19
</textarea><textarea style="display:none" id="q_1646205417">-- Using spatial unit vectors for coordinate cuts.
-- Find galaxies in a given area of the sky, using a coordinate cut
-- in the unit vector cx,cy,cz that corresponds to a specific RA range.
-- Another simple query that uses math in the WHERE clause.
--
-- NOTE: This query must be run in batch mode, i.e. using the Submit button
-- because it takes too long to execute in Quick mode.
SELECT TOP 100 colc_g, colc_r
FROM Galaxy
WHERE
(-0.466 * cx + 0.689 * cy>=0)
and (-0.385 * cx - 0.173 * cy <0)
</textarea><textarea style="display:none" id="q_150519266">-- Find CVs using colors.
-- Search for Cataclysmic Variables and pre-CVs with White Dwarfs and
-- very late secondaries. Just uses some simple color cuts from Paula Szkody.
-- Another simple query that uses math in the WHERE clause
SELECT TOP 100 run,
camCol,
rerun,
field,
objID,
u, g, r, i, z,
ra, dec -- Just get some basic quantities
FROM PhotoPrimary -- From all primary detections, regardless of class
WHERE u - g < 0.4
and g - r < 0.7
and r - i > 0.4
and i - z > 0.4 -- that meet the color criteria
</textarea><textarea style="display:none" id="q_943895088">-- Getting a subsample of the data.
--
-- Uses the integer short object id (obj) - which is the least significant bits
-- of the long objID - and the '%' operator (remainder) to get every 1000th
-- object.
-- NOTE: THIS IS NOT A TRULY RANDOM SAMPLE!
SELECT TOP 100 u, g, r, i, z
FROM Galaxy with (nolock)
WHERE (objID%1000) = 1
AND (r between 18 and 21)
</textarea><textarea style="display:none" id="q_1380995089">-- Low-z QSO candidates using color cuts.
-- from Gordon Richards.
-- Also a simple query with a long WHERE clause.
SELECT TOP 1000 g, run, rerun, camcol, field, objID
FROM
Galaxy
WHERE (
(g <= 22) and
(u-g >= -0.27) and (u-g < 0.71) and
(g-r >= -0.24) and (g-r < 0.35) and
(r-i >= -0.27) and (r-i < 0.57) and
(i-z >= -0.35) and (i-z < 0.70)
)</textarea><textarea style="display:none" id="q_2032074038">-- Get object velocities and errors.
-- This is also a simple query that uses a WHERE clause.
-- However, now we perform a more complex mathematical operation.
SELECT TOP 10
run, -- get a bunch of quantities
camCol,
field,
objID,
rowC, colC, rowV, colV, rowVErr, colVErr,
flags,
psfMag_u, psfMag_g, psfMag_r, psfMag_i, psfMag_z,
psfMagErr_u, psfMagErr_g, psfMagErr_r, psfMagErr_i, psfMagErr_z
FROM PhotoPrimary
WHERE ((rowv * rowv) / (rowvErr * rowvErr) +
(colv * colv) / (colvErr * colvErr) > 4)
-- where the velocities are reliable
</textarea><textarea style="display:none" id="q_77418842">-- Finding galaxies by their emission lines:
--
-- SDSS-III handles searches by spectral lines differently than previous
-- releases. In addition, spectral lines for galaxies and stars are
-- identified through different processes. See the "Spectra of Red
-- Stars" sample query for an example of using stellar spectra.
--
-- Spectral lines for galaxies are calculated using the MPA-JHU
-- spectroscopic reanalysis (Tremonti et al. 2004; Brinchmann et al. 2004)
-- and are stored in the galSpecLine table. For more on how spectral lines
-- of galaxies are found, see the Galspec page of the sdss3.org website.
--
-- This query selects galaxy spectra with high internal reddening,
-- as measured by the standard Balmer decrement technique. It
-- makes use of the galSpec tables for the measurements of
-- galaxy lines. In this case we use galSpecLine, which has
-- emission line measurements.
SELECT
s.plate, s.fiberid, s.mjd, s.z, s.zwarning,
g.h_beta_flux, g.h_beta_flux_err,
g.h_alpha_flux, g.h_alpha_flux_err
FROM GalSpecLine AS g
JOIN dbo.SpecObj AS s ON s.specobjid = g.specobjid
WHERE
h_alpha_flux > h_alpha_flux_err*5
AND h_beta_flux > h_beta_flux_err*5
AND h_beta_flux_err > 0
AND h_alpha_flux > 10.*h_beta_flux
AND s.class = 'GALAXY'
AND s.zwarning = 0
</textarea><textarea style="display:none" id="q_436084239">-- Moving objects consistent with an asteroid.
-- Also a simple query, but we introduce the 'as' syntax, which allows us to
-- name derived quantities in the result file.
--
-- NOTE: Since asteroids are rare objects in the SDSS data, this query will
-- take a long time to run without the "TOP 10" and should be executed
-- in batch mode (with the Submit button).
SELECT TOP 10
objID,
sqrt( power(rowv,2) + power(colv, 2) ) as velocity
FROM PhotoObj
WHERE
(power(rowv,2) + power(colv, 2)) between 50 and 1000
</textarea><textarea style="display:none" id="q_352254942">-- Find quasars in imaging data.
-- as specified by Xiaohui Fan et.al.
-- A rather straightforward query, just with many conditions.
SELECT TOP 100 run,
camCol,
rerun,
field,
objID,
u, g, r, i, z,
ra, dec
FROM Star -- or Galaxy
WHERE ( u - g > 2.0 or u > 22.3 )
and ( i < 19 )
and ( i > 0 )
and ( g - r > 1.0 )
and ( r - i <
(0.08 + 0.42 * (g - r - 0.96) )
or g - r > 2.26 )
and ( i - z < 0.25 )
</textarea><textarea style="display:none" id="q_1677687603">-- Using object counting and logic in a query.
-- Find all objects similar to the colors of a quasar at 5.5<redshift<6.5.
-- An area restriction is added so the query will run in the Quick queue.
SELECT count(*) as 'total',
sum( case when (Type=3) then 1 else 0 end) as 'Galaxies',
sum( case when (Type=6) then 1 else 0 end) as 'Stars',
sum( case when (Type not in (3,6)) then 1 else 0 end) as 'Other'
FROM PhotoPrimary -- for each object
WHERE
(ra between 180 and 190) and (dec between -5 and 5)
and (( u - g > 2.0) or (u > 22.3) ) -- apply the quasar color cut.
and ( i between 0 and 19 )
and ( g - r > 1.0 )
and ( (r - i < 0.08 + 0.42 * (g - r - 0.96)) or (g - r > 2.26 ) )
and ( i - z < 0.25 )
</textarea><textarea style="display:none" id="q_1019428081">-- Find galaxies that are blended with a star.
-- Output the deblended galaxy magnitudes.
-- This query introduces the use of multiple tables or views. You can assign
-- nicknames to tables as in the FROM clause below. Since you are using
-- multiple tables, you must specify which table each quantity in the SELECT
-- clause comes from. The query illustrates the JOIN syntax between
-- the two tables, which requires that a common quantity that is present in
-- both tables be equal, in this case their common parent object.
SELECT top 1000 G.ObjID, G.u, G.g, G.r, G.i, G.z
FROM Galaxy G -- compare Galaxy and Star
JOIN Star S ON G.parentID = S.parentID -- using the same parent
WHERE
G.parentID > 0 -- if the galaxy has a "parent", this object was deblended
</textarea><textarea style="display:none" id="q_1340958328">-- Stars selected using Field criteria.
-- Give me the PSF colors of all stars brighter than g=20 that have PSP_STATUS = 2.
-- Another simple multi-table query.
SELECT TOP 1000
s.psfMag_g, -- or whatever you want from each object
s.run,
s.camCol,
s.rerun,
s.field
FROM Star s
JOIN Field f ON s.fieldID = f.fieldID
WHERE
s.psfMag_g < 20
and f.pspStatus = 2
</textarea><textarea style="display:none" id="q_1563485422">-- Objects selected by cuts on three tables.
-- Find the parameters for all objects in a selected field with
-- desired PSF width and range of columns.
-- Now we are using three tables, but it is still a simple query.
SELECT TOP 1000
f.run,
f.rerun,
f.camCol,
f.field,
p.objID,
p.ra,
p.dec,
p.Rowc,
p.Colc,
p.u,
p.modelMagErr_u ,
p.g,
p.modelMagErr_g,
p.r,
p.modelMagErr_r,
p.petroMag_r - p.extinction_r,
p.petroMagErr_r,
p.i,
p.modelMagErr_i,
p.z,
f.psfWidth_r,
r.stripe,
r.strip
FROM
photoObj p
JOIN field f ON f.fieldid = p.fieldid
JOIN run r ON r.run=f.run
WHERE
f.psfWidth_r > 1.2
and p.colc > 400.0
</textarea><textarea style="display:none" id="q_466532201">-- Find all objects within 30 arcseconds of one another
-- that have very similar colors: that is where the color ratios
-- u-g, g-r, r-I are less than 0.05m. This query introduces the
-- Neighbors table, which is a pre-computed list of the nearest
-- neighbors of each object within 30 arcseconds.
SELECT TOP 10 P.ObjID as objid1, L.ObjID as objid2, N.distance
FROM PhotoPrimary P -- P is the primary object
JOIN Neighbors N ON P.ObjID = N.ObjID -- N is the neighbor link
JOIN PhotoPrimary L ON L.ObjID = N.NeighborObjID -- L is the lens candidate of P
WHERE
P.ObjID < L. ObjID -- avoid duplicates
and abs((P.u-P.g)-(L.u-L.g))<0.05 -- L and P have similar spectra
and abs((P.g-P.r)-(L.g-L.r))<0.05
and abs((P.r-P.i)-(L.r-L.i))<0.05
and abs((P.i-P.z)-(L.i-L.z))<0.05
</textarea><textarea style="display:none" id="q_1381126224">-- Find stars with multiple measurements with magnitude variations >0.1.
-- Note that this runs very slowly unless explicit workarounds are included
-- for some SQLServer Optimizer bugs, which are NOT included here
SELECT TOP 100
S1.objID as objID1, S2.objID as ObjID2 -- select object IDs of star and its pair
FROM Star as S1, -- the primary star
photoObj as S2, -- the second observation of the star
neighbors as N -- the neighbor record
WHERE S1.objID = N.objID -- insist the stars are neighbors
and S2.objID = N.neighborObjID -- using precomputed neighbors table
and distance < 0.5/60 -- distance is 0.5 arc second or less
and S1.run != S2.run -- observations are two different runs
and S2.type = dbo.fPhotoType('Star') -- S2 is indeed a star
and S1.u between 1 and 27 -- S1 magnitudes are reasonable
and S1.g between 1 and 27
and S1.r between 1 and 27
and S1.i between 1 and 27
and S1.z between 1 and 27
and S2.u between 1 and 27 -- S2 magnitudes are reasonable.
and S2.g between 1 and 27
and S2.r between 1 and 27
and S2.i between 1 and 27
and S2.z between 1 and 27
and ( -- and one of the colors is different.
abs(S1.u-S2.u) > .1 + (abs(S1.Err_u) + abs(S2.Err_u))
or abs(S1.g-S2.g) > .1 + (abs(S1.Err_g) + abs(S2.Err_g))
or abs(S1.r-S2.r) > .1 + (abs(S1.Err_r) + abs(S2.Err_r))
or abs(S1.i-S2.i) > .1 + (abs(S1.Err_i) + abs(S2.Err_i))
or abs(S1.z-S2.z) > .1 + (abs(S1.Err_z) + abs(S2.Err_z))
)
</textarea><textarea style="display:none" id="q_570846738">-- Checking for errors using flags.
-- Another useful query is to see if the errors on moving (or
-- apparently moving) objects are correct. For example, it used to be that
-- some known QSOs were being flagged as moving objects. One way to look for
-- such objects is to compare the velocity to the error in velocity and see if
-- the "OBJECT1_MOVED" or "OBJECT2_BAD_MOVING_FIT" is set.
-- This query introduces bitwise logic for flags, and uses the 'as' syntax to
-- make the query more readable. Note that if a flag is not set, the value
-- will be zero. If you want to ensure multiple flags are not set, you can
-- either check that each individually is zero, or that their sum is zero.
-- (From Gordon Richards)
--
-- NOTE: A caveat about using functons (like fPhotoFlags) is that if your
-- query is selecting a very large number of rows (e.g. hundreds of
-- thousands or millions) then it's that many function calls, and
-- this will slow down the query execution significantly. In that
-- case, you should replace the function call with its equivalent
-- binary bitmask, e.g. if you run the query (with Quick button)
-- SELECT (dbo.fPhotoFlags('MOVED') + dbo.fPhotoFlags('BAD_MOVING_FIT'))
-- you will get the value 36507222016, which you can substitute in
-- first line of the WHERE clause below as:
-- (flags & 36507222016) > 0
-- to avoid zillions of function calls.
SELECT TOP 1000
run,
rerun,
camcol,
field,
objID,
ra, dec,
rowv, colv,
rowvErr, colvErr,
i,
(flags & dbo.fPhotoFlags('MOVED')) as MOVED,
(flags & dbo.fPhotoFlags('BAD_MOVING_FIT')) as BAD_MOVING_FIT
FROM Galaxy
WHERE
(flags & (dbo.fPhotoFlags('MOVED') + dbo.fPhotoFlags('BAD_MOVING_FIT'))) > 0
and (rowv * rowv + colv * colv) >=
(rowvErr * rowvErr + colvErr * colvErr)
</textarea><textarea style="display:none" id="q_1884815287">-- Elliptical galaxies based on model fits.
-- Find all galaxies with a deVaucouleours profile and the
-- photometric colors consistent with an elliptical galaxy.
-- This query has many conditions, and also shows more of the
-- bitwise logic necessary for dealing with flags.
SELECT TOP 100 ObjID
FROM Galaxy as G
WHERE
G.lnlDev_r > G.lnlExp_r + 0.1
-- the likelihood of the deVaucouleours profile fit is 10% greater than the likelihood of the exponential fit
and G.lnlExp_r > -999
-- and the likelihoods are actually meaningful
and (G.flags & (dbo.fPhotoFlags('BINNED1') + dbo.fPhotoFlags('BINNED2') + dbo.fPhotoFlags('BINNED4'))) > 0
--and it is detected from at least one of the binned images ???
and (G.flags & ( dbo.fPhotoFlags('BLENDED') + dbo.fPhotoFlags('NODEBLEND') + dbo.fPhotoFlags('CHILD'))) != dbo.fPhotoFlags('BLENDED')
--and, if it is blended, it is either a child or not deblended further ??
and (G.flags & (dbo.fPhotoFlags('EDGE') + dbo.fPhotoFlags('SATURATED'))) = 0
-- and it is not near a ccd edge or saturated, where measurements may be bad
and G.petroMag_i > 17.5
-- and it is fainter than 17.5 in i-band
and (G.petroMag_r > 15.5 or G.petror50_r > 2)
and (G.petroMag_r > 0 and G.g > 0 and G.r > 0 and G.i > 0)
and ( (G.petroMag_r - G.extinction_r) < 19.2
and (G.petroMag_r - G.extinction_r <
(13.1 + (7/3)*(G.g - G.r) + 4 *(G.r - G.i) - 4 * 0.18 ) )
and ( (G.r - G.i - (G.g - G.r)/4 - 0.18) < 0.2 )
and ( (G.r - G.i - (G.g - G.r)/4 - 0.18) > -0.2 ) )
or ( (G.petroMag_r - G.extinction_r < 19.5)
and ( (G.r - G.i - (G.g - G.r)/4 - 0.18) >
(0.45 - 4*(G.g - G.r) ) )
and ( (G.g - G.r) > (1.35 + 0.25 *(G.r - G.i) ) ) )
-- and many constraints on colors and mags are met to make it have
-- elliptical-type colors.
</textarea><textarea style="display:none" id="q_689792689">-- Galaxies with bluer centers.
-- by Michael Strauss. For all galaxies
-- with r_Petro < 18, not saturated, not bright, and not edge, give me those
-- with centers appreciably bluer than their outer parts, i.e., define the
-- center color as: u_psf - g_psf and define the outer color as: u_model -
-- g_model; give me all objs which have (u_model - g_model) - (u_psf - g_psf)
-- < -0.4
-- Another flags-based query.
SELECT TOP 1000
colc_u, colc_g, objID
FROM Galaxy
WHERE
( Flags & (dbo.fPhotoFlags('SATURATED') +
dbo.fPhotoFlags('BRIGHT') +
dbo.fPhotoFlags('EDGE')) ) = 0
and petrorad_r < 18
and ((colc_u - colc_g) - (psfMag_u - psfMag_g)) < -0.4</textarea><textarea style="display:none" id="q_193732499">-- Diameter-limited sample of galaxies
-- from James Annis.
-- Another query that makes extensive use of photo flags to get a sample
-- of galaxies within a size range as specified by their i-band Petrosian
-- radius.
SELECT TOP 100
run,
camCol,
rerun,
field,
objID,
ra,
dec
FROM Galaxy
WHERE ( flags & (dbo.fPhotoFlags('BINNED1')
+ dbo.fPhotoFlags('BINNED2')
+ dbo.fPhotoFlags('BINNED4')) ) > 0
and ( flags & (dbo.fPhotoFlags('BLENDED')
+ dbo.fPhotoFlags('NODEBLEND')
+ dbo.fPhotoFlags('CHILD')) ) != dbo.fPhotoFlags('BLENDED')
and ( ( (flags & dbo.fPhotoFlags('NOPETRO') = 0)
and petrorad_i > 15)
or ( (flags & dbo.fPhotoFlags('NOPETRO') > 0)
and petrorad_i > 7.5)
or ( (flags & dbo.fPhotoFlags('TOO_LARGE') > 0)
and petrorad_i > 2.5)
or
( (flags & dbo.fPhotoFlags('SATURATED') = 0)
and petrorad_i > 17.5) )
</textarea><textarea style="display:none" id="q_883674423">-- Extremely red galaxies.
-- from James Annis.
-- Similar to the diameter limited sample query but selects galaxies that
-- are red (i-z color greater than a certain threshold).
SELECT TOP 1000
g.run,
g.camCol,
g.rerun,
g.field,
g.objID,
g.ra, g.dec
FROM Field f, Galaxy g
WHERE
g.fieldID = f.fieldID
and ( g.flags & (dbo.fPhotoFlags('BINNED1')
+ dbo.fPhotoFlags('BINNED2')
+ dbo.fPhotoFlags('BINNED4')) ) > 0
and ( g.flags & (dbo.fPhotoFlags('BLENDED')
+ dbo.fPhotoFlags('NODEBLEND')
+ dbo.fPhotoFlags('CHILD')) ) != dbo.fPhotoFlags('BLENDED')
and ( g.flags & (dbo.fPhotoFlags('COSMIC_RAY')
+ dbo.fPhotoFlags('INTERP')) ) = 0
and f.psfWidth_r < 1.5
and (g.i - g.z > 1.0 )
</textarea><textarea style="display:none" id="q_498791126">-- A version of the LRG sample.
-- by James Annis.
-- Another query with many conditions and flag tests that selects Luminous
-- Red Galaxies (LRGs).
SELECT TOP 100
run,
camCol,
rerun,
field,
objID,
ra,
dec
FROM Galaxy
WHERE ( ( flags & (dbo.fPhotoFlags('BINNED1')
+ dbo.fPhotoFlags('BINNED2')
+ dbo.fPhotoFlags('BINNED4')) ) > 0
and ( flags & (dbo.fPhotoFlags('BLENDED')
+ dbo.fPhotoFlags('NODEBLEND')
+ dbo.fPhotoFlags('CHILD')) ) != dbo.fPhotoFlags('BLENDED')
and ( flags & (dbo.fPhotoFlags('EDGE')
+ dbo.fPhotoFlags('SATURATED')) ) = 0
and petroMag_i > 17.5
and (petroMag_r > 15.5 or petror50_r > 2)
and (petroMag_r > 0 and g > 0 and r > 0 and i > 0)
and ( (petroMag_r-extinction_r) < 19.2
and (petroMag_r - extinction_r <
(13.1 + (7/3) * (dered_g - dered_r) + 4 * (dered_r - dered_i) - 4 * 0.18) )
and ( (dered_r - dered_i - (dered_g - dered_r)/4 - 0.18) < 0.2)
and ( (dered_r - dered_i - (dered_g - dered_r)/4 - 0.18) > -0.2)
--dered_ quantities already include extinction
and ( (petroMag_r - extinction_r +
2.5 * LOG10(2 * 3.1415 * petror50_r * petror50_r)) < 24.2) )
or ( (petroMag_r - extinction_r < 19.5)
and ( (dered_r - dered_i - (dered_g - dered_r)/4 - 0.18) > (0.45 - 4 * (dered_g - dered_r)) )
and ( (dered_g - dered_r) > (1.35 + 0.25 * (dered_r - dered_i)) ) )
and ( (petroMag_r - extinction_r +
2.5 * LOG10(2 * 3.1415 * petror50_r * petror50_r) ) < 23.3 ) )
</textarea><textarea style="display:none" id="q_620022539">-- Spectra of Red Stars
--
-- SDSS-III handles searches by spectral lines differently than previous
-- releases. In addition, spectral lines for galaxies and stars are
-- identified through different processes. See the "Galaxies with
-- Emission Lines" sample query for an example of using galaxy spectra.
--
-- Spectral lines for stars are calculated using the SEGUE Stellar Parameter
-- Pipeline (SSPP; Lee et al. 2008) and are stored in the sppLines
-- table. For more on how spectral lines of stars are found, see
-- the SSPP page of the sdss3.org website.
-- This query selects red stars (spectral type K), with large
-- CaII triplet eq widths, with low errors on the CaII triplet
-- equivalent widths.
SELECT
sl.plate,sl.mjd,sl.fiber,
sl.caIIKside,sl.caIIKerr,sl.caIIKmask,
sp.fehadop,sp.fehadopunc,sp.fehadopn,
sp.loggadopn,sp.loggadopunc
FROM sppLines AS sl
JOIN sppParams AS sp ON sl.specobjid = sp.specobjid
WHERE
fehadop < -3.5
AND fehadopunc between 0.01
and 0.5 and fehadopn > 3
</textarea><textarea style="display:none" id="q_1606095120">-- Galaxy counts on HTM grid.
--
-- Create a count of galaxies for each of the Hierarchical Triangular Mesh (HTM) triangles.
-- Galaxies should satisfy a certain color cut like 0.7u-0.5g-0.2i<1.25 && r<21.75, output
-- it in a form adequate for visualization.
SELECT (htmID / power(2,24)) as htm_8 ,
-- group by 8-deep HTMID (rshift HTM by 12)
avg(ra) as ra,
avg(dec) as [dec],
count(*) as pop -- return center point and count for display
FROM Galaxy -- only look at galaxies
WHERE
-- RA/dec cut added to make query run in Quick mode
(ra between 180 and 181 and dec between -1 and 1) and
(0.7*u - 0.5*g - 0.2*i) < 1.25 -- meeting this color cut
and r < 21.75 -- brighter than 21.75 magnitude in red band.
group by (htmID /power(2,24)) -- group into 8-deep HTM buckets.
</textarea><textarea style="display:none" id="q_2056596239">-- Binary Stars Colors.
--
-- Find binary stars with specific colors.
-- At least one of them should have the colors (meets Paul Szkody's color cut) of a white dwarf.
SELECT TOP 100 s1.objID as s1, s2.objID as s2
FROM Star S1 -- S1 is the white dwarf
JOIN Neighbors N ON S1.objID = N. objID -- N is the precomputed neighbors link
JOIN Star S2 ON S2.objID = N.NeighborObjID -- S2 is the second star
WHERE
N.neighborType = dbo.fPhotoType('Star') -- and S2 is a star
and N.distance < .05 -- the 3 arcsecond test
and ((S1.u - S1.g) < 0.4 ) -- and S1 meets the color cut for
and (S1.g - S1.r) < 0.7 -- white dwarfs.
and (S1.r - S1.i) > 0.4
and (S1.i - S1.z) > 0.4
</textarea><textarea style="display:none" id="q_1200129878">-- Galaxies unsaturated near (given) coordinates.
--
-- Find galaxies without saturated pixels within 1' of a given point.
-- ra=185.0, dec=-0.5. This query uses a function fGetNearbyObjEq,
-- which takes 3 arguments (ra,dec, distance in arcmin); this function uses
-- the Neighbors table. The Neighbors table and the Galaxy table have in
-- common the objID, so we have to select objects from both where the objIDs
-- are the same. The output of the function is a table with the Galaxy Object
-- ID and distance in arcmin from the input. This query introduces the use of
-- a JOIN to combine table contents. Also, we use the 'ORDER BY' syntax,
-- which will sort the output.
SELECT TOP 100 G.objID, GN.distance
FROM Galaxy AS G
JOIN dbo.fGetNearbyObjEq(185.,-0.5, 1) AS GN -- this function outputs a table, so we have to do a join
ON G.objID = GN.objID -- get objects from temporary neighbors table GN with desired ObjID
WHERE
(G.flags & dbo.fPhotoFlags('saturated')) = 0 -- and the object is not saturated. f.PhotoFlags is a function that interprets the flag bits.
ORDER BY distance -- sort these by distance
</textarea><textarea style="display:none" id="q_1036893522">-- Search near BCG galaxies.
--
-- For each galaxy in the BCG data set (brightest cluster galaxy),
-- in 160<right ascension<170, -25<declination<35 count the number of
-- galaxies within 30" of it that have a photoz within 0.05
-- of that galaxy.
-- This query has a very complex WHERE clause.
SELECT TOP 1000 G.objID, COUNT(N.NeighborObjID) AS pop
FROM Galaxy AS G -- first gravitational lens candidate
JOIN Neighbors AS N ON G.objID = N.objID -- precomputed list of neighbors
JOIN Galaxy AS U ON U.objID = N.neighborObjID -- a neighbor galaxy of G
JOIN photoZ AS Gpz ON G.objID = Gpz.objID -- photoZ of G.
JOIN photoZ AS Npz ON U.objID = Npz.objID -- neighbor photoZ
WHERE
G.ra BETWEEN 160 AND 170
AND G.dec BETWEEN -5 AND 5
AND N.objID < N.neighborObjID -- 30 arcseconds of one another.
AND ABS(Gpz.Z - Npz.Z) < 0.05 -- restrict the photoZ differences
AND (G.flags & (dbo.fPhotoFlags('BINNED1') + dbo.fPhotoFlags('BINNED2') + dbo.fPhotoFlags('BINNED4'))) > 0
--and it is detected from at least one of the binned images
AND (G.flags & ( dbo.fPhotoFlags('BLENDED') + dbo.fPhotoFlags('NODEBLEND') + dbo.fPhotoFlags('CHILD'))) != dbo.fPhotoFlags('BLENDED')
--and, if it is blended, it is either a child or not deblended further ??
AND (G.flags & (dbo.fPhotoFlags('EDGE') + dbo.fPhotoFlags('SATURATED'))) = 0
-- and it is not near a ccd edge or saturated, where measurements may be bad
-- and apply color cut for a BCG courtesy of James Annis of Fermilab
AND G.petroMag_i > 17.5
AND (G.petroMag_r > 15.5 or G.petror50_r > 2)
AND (G.petroMag_r < 30 AND G.g < 30 AND G.r < 30 AND G.i < 30)
AND (G.r < 19.2
AND ( 1=1 or -- huh?
(G.r < (13.1 + (7/3)*(G.g - G.r) +
-- deRed_r < 13.1 + 0.7 / 0.3 * deRed_gr
4 *(G.r - G.i - 0.18 ))
-- 1.2 / 0.3 * deRed_ri
AND (( G.r - G.i - (G.g - G.r)/4 - 0.18) BETWEEN -0.2 AND 0.2 )
AND ((G.r +
-- petSB - deRed_r + 2.5 log10(2Pi*petror50^2)
2.5 * LOG( 2 * 3.1415 * G.petror50_r * G.petror50_r )) < 24.2 )
)
or
( (G.r < 19.5 )
AND (( G.r - G.i -(G.g - G.r)/4 -.18) >
-- - deRed_gr/4 - 0.18
-- cperp = deRed_ri
(0.45 - 4*( G.g - G.r)))
-- 0.45 - deRed_gr/0.25
AND ((G.g - G.r) > ( 1.35 + 0.25 *(G.r - G.i)))
AND ((G.r +
-- petSB - deRed_r + 2.5 log10(2Pi*petror50^2)
2.5 * LOG( 2 * 3.1415 * G.petror50_r * G.petror50_r )) < 23.3 )
)) )
GROUP BY G.objID
</textarea><textarea style="display:none" id="q_1368842829">-- The detectionIndex table contains all detections of a given physical object,
-- which is uniquely identified by the "thingid". In order to extract photometry,
-- you need a join with the PhotoObjAll table, using the objid.
-- There is also a flag field called isPrimary, which is 1 for the object that
-- is found on a primary polygon/field, all the other detections have 0 in this field.
-- Here is a compound query to find all time series around a certain object with a thingid= 97423000
SELECT
LTRIM(STR(mjd_r,20,2)) AS MJD,
dbo.fSDSS(p.objId) AS ID,
modelMag_g, modelMagErr_g,
modelMag_r, modelMagErr_r,
modelMag_i, modelMagErr_i, p.ra, p.dec
INTO #list
FROM detectionindex d
JOIN PhotoObjAll p ON d.objid=p.objid
JOIN Field f ON p.fieldid=f.fieldid
WHERE d.thingid=97423000
ORDER BY 1
GO
--
-- Now find objects near each of the detections
--
SELECT a.*, b.*
FROM #list a
CROSS APPLY dbo.fGetNearbyObjEq(a.ra, a.dec, 0.1) b
</textarea>
<textarea style="display:none" id="q_442485668">-- Find unique objects in an RA/Dec box.
-- PhotoPrimary is a view which selects only unique objects.
-- The full list of good detections including duplicates is in PhotoObj
-- A basic SELECT-FROM-WHERE query.
SELECT TOP 100 objID, -- Get the unique object ID,
field, ra, dec -- the field number, and coordinates
FROM PhotoPrimary -- From the photometric data
WHERE
ra > 185. and ra < 185.1 and dec > 15. and dec < 15.1 </textarea><textarea style="display:none" id="q_2039614472">-- Galaxies meeting two simple criteria.
-- Find all galaxies brighter than r magnitude 22, where the local
-- extinction is > 0.175. This is a simple query that uses a WHERE clause,
-- but now two conditions that must be met simultaneously.
SELECT TOP 10 objID
FROM Galaxy
WHERE
r < 22 -- r IS NOT deredenned
and extinction_r > 0.175 -- extinction more than 0.175
</textarea><textarea style="display:none" id="q_1763264299">-- Find specific types of quasars using spectroscopy.
-- The easiest way to find quasars is by finding objects whose spectra have
-- been classified as quasars. This sample query searches the SpecObj
-- table for the IDs and redshifts of objects with the class column equal to 'QSO'
SELECT TOP 100 specObjID, z
FROM SpecObj
WHERE class = 'QSO' AND zWarning = 0
</textarea><textarea style="display:none" id="q_2013120862">-- Using the BETWEEN syntax.
-- Find all galaxies in a certain area of the sky that also meet other
-- criteria in their measured parameters. This query intriduces the
-- BETWEEN construct to specify a range of values.
SELECT TOP 100 objID, ra, dec, cModelMag_g
FROM Galaxy
WHERE ra BETWEEN 178 AND 180
AND dec < 0
AND cModelMag_g BETWEEN 18 AND 19
</textarea><textarea style="display:none" id="q_930225692">-- Using spatial unit vectors for coordinate cuts.
-- Find galaxies in a given area of the sky, using a coordinate cut
-- in the unit vector cx,cy,cz that corresponds to a specific RA range.
-- Another simple query that uses math in the WHERE clause.
--
-- NOTE: This query must be run in batch mode, i.e. using the Submit button
-- because it takes too long to execute in Quick mode.
SELECT TOP 100 colc_g, colc_r
FROM Galaxy
WHERE
(-0.466 * cx + 0.689 * cy>=0)
and (-0.385 * cx - 0.173 * cy <0)
</textarea><textarea style="display:none" id="q_129227591">-- Find CVs using colors.
-- Search for Cataclysmic Variables and pre-CVs with White Dwarfs and
-- very late secondaries. Just uses some simple color cuts from Paula Szkody.
-- Another simple query that uses math in the WHERE clause
SELECT TOP 100 run,
camCol,
rerun,
field,
objID,
u, g, r, i, z,
ra, dec -- Just get some basic quantities
FROM PhotoPrimary -- From all primary detections, regardless of class
WHERE u - g < 0.4
and g - r < 0.7
and r - i > 0.4
and i - z > 0.4 -- that meet the color criteria
</textarea><textarea style="display:none" id="q_1795754421">-- Getting a subsample of the data.
--
-- Uses the integer short object id (obj) - which is the least significant bits
-- of the long objID - and the '%' operator (remainder) to get every 1000th
-- object.
-- NOTE: THIS IS NOT A TRULY RANDOM SAMPLE!
SELECT TOP 100 u, g, r, i, z
FROM Galaxy with (nolock)
WHERE (objID%1000) = 1
AND (r between 18 and 21)
</textarea><textarea style="display:none" id="q_787192452">-- Low-z QSO candidates using color cuts.
-- from Gordon Richards.
-- Also a simple query with a long WHERE clause.
SELECT TOP 1000 g, run, rerun, camcol, field, objID
FROM
Galaxy
WHERE (
(g <= 22) and
(u-g >= -0.27) and (u-g < 0.71) and
(g-r >= -0.24) and (g-r < 0.35) and
(r-i >= -0.27) and (r-i < 0.57) and
(i-z >= -0.35) and (i-z < 0.70)
)</textarea><textarea style="display:none" id="q_268548153">-- Get object velocities and errors.
-- This is also a simple query that uses a WHERE clause.
-- However, now we perform a more complex mathematical operation.
SELECT TOP 10
run, -- get a bunch of quantities
camCol,
field,
objID,
rowC, colC, rowV, colV, rowVErr, colVErr,
flags,
psfMag_u, psfMag_g, psfMag_r, psfMag_i, psfMag_z,
psfMagErr_u, psfMagErr_g, psfMagErr_r, psfMagErr_i, psfMagErr_z
FROM PhotoPrimary
WHERE ((rowv * rowv) / (rowvErr * rowvErr) +
(colv * colv) / (colvErr * colvErr) > 4)
-- where the velocities are reliable
</textarea><textarea style="display:none" id="q_1047280483">-- Finding galaxies by their emission lines:
--
-- SDSS-III handles searches by spectral lines differently than previous
-- releases. In addition, spectral lines for galaxies and stars are
-- identified through different processes. See the "Spectra of Red
-- Stars" sample query for an example of using stellar spectra.
--
-- Spectral lines for galaxies are calculated using the MPA-JHU
-- spectroscopic reanalysis (Tremonti et al. 2004; Brinchmann et al. 2004)
-- and are stored in the galSpecLine table. For more on how spectral lines
-- of galaxies are found, see the Galspec page of the sdss3.org website.
--
-- This query selects galaxy spectra with high internal reddening,
-- as measured by the standard Balmer decrement technique. It
-- makes use of the galSpec tables for the measurements of
-- galaxy lines. In this case we use galSpecLine, which has
-- emission line measurements.
SELECT
s.plate, s.fiberid, s.mjd, s.z, s.zwarning,
g.h_beta_flux, g.h_beta_flux_err,
g.h_alpha_flux, g.h_alpha_flux_err
FROM GalSpecLine AS g
JOIN dbo.SpecObj AS s ON s.specobjid = g.specobjid
WHERE
h_alpha_flux > h_alpha_flux_err*5
AND h_beta_flux > h_beta_flux_err*5
AND h_beta_flux_err > 0
AND h_alpha_flux > 10.*h_beta_flux
AND s.class = 'GALAXY'
AND s.zwarning = 0
</textarea><textarea style="display:none" id="q_191604836">-- Moving objects consistent with an asteroid.
-- Also a simple query, but we introduce the 'as' syntax, which allows us to
-- name derived quantities in the result file.
--
-- NOTE: Since asteroids are rare objects in the SDSS data, this query will
-- take a long time to run without the "TOP 10" and should be executed
-- in batch mode (with the Submit button).
SELECT TOP 10
objID,
sqrt( power(rowv,2) + power(colv, 2) ) as velocity
FROM PhotoObj
WHERE
(power(rowv,2) + power(colv, 2)) between 50 and 1000
</textarea><textarea style="display:none" id="q_1893814627">-- Find quasars in imaging data.
-- as specified by Xiaohui Fan et.al.
-- A rather straightforward query, just with many conditions.
SELECT TOP 100 run,
camCol,
rerun,
field,
objID,
u, g, r, i, z,
ra, dec
FROM Star -- or Galaxy
WHERE ( u - g > 2.0 or u > 22.3 )
and ( i < 19 )
and ( i > 0 )
and ( g - r > 1.0 )
and ( r - i <
(0.08 + 0.42 * (g - r - 0.96) )
or g - r > 2.26 )
and ( i - z < 0.25 )
</textarea><textarea style="display:none" id="q_1199374736">-- Using object counting and logic in a query.
-- Find all objects similar to the colors of a quasar at 5.5<redshift<6.5.
-- An area restriction is added so the query will run in the Quick queue.
SELECT count(*) as 'total',
sum( case when (Type=3) then 1 else 0 end) as 'Galaxies',
sum( case when (Type=6) then 1 else 0 end) as 'Stars',
sum( case when (Type not in (3,6)) then 1 else 0 end) as 'Other'
FROM PhotoPrimary -- for each object
WHERE
(ra between 180 and 190) and (dec between -5 and 5)
and (( u - g > 2.0) or (u > 22.3) ) -- apply the quasar color cut.
and ( i between 0 and 19 )
and ( g - r > 1.0 )
and ( (r - i < 0.08 + 0.42 * (g - r - 0.96)) or (g - r > 2.26 ) )
and ( i - z < 0.25 )
</textarea><textarea style="display:none" id="q_1733737046">-- Find galaxies that are blended with a star.
-- Output the deblended galaxy magnitudes.
-- This query introduces the use of multiple tables or views. You can assign
-- nicknames to tables as in the FROM clause below. Since you are using
-- multiple tables, you must specify which table each quantity in the SELECT
-- clause comes from. The query illustrates the JOIN syntax between
-- the two tables, which requires that a common quantity that is present in
-- both tables be equal, in this case their common parent object.
SELECT top 1000 G.ObjID, G.u, G.g, G.r, G.i, G.z
FROM Galaxy G -- compare Galaxy and Star
JOIN Star S ON G.parentID = S.parentID -- using the same parent
WHERE
G.parentID > 0 -- if the galaxy has a "parent", this object was deblended
</textarea><textarea style="display:none" id="q_317286293">-- Stars selected using Field criteria.
-- Give me the PSF colors of all stars brighter than g=20 that have PSP_STATUS = 2.
-- Another simple multi-table query.
SELECT TOP 1000
s.psfMag_g, -- or whatever you want from each object
s.run,
s.camCol,
s.rerun,
s.field
FROM Star s
JOIN Field f ON s.fieldID = f.fieldID
WHERE
s.psfMag_g < 20
and f.pspStatus = 2
</textarea><textarea style="display:none" id="q_1874540969">-- Objects selected by cuts on three tables.
-- Find the parameters for all objects in a selected field with
-- desired PSF width and range of columns.
-- Now we are using three tables, but it is still a simple query.
SELECT TOP 1000
f.run,
f.rerun,
f.camCol,
f.field,
p.objID,
p.ra,
p.dec,
p.Rowc,
p.Colc,
p.u,
p.modelMagErr_u ,
p.g,
p.modelMagErr_g,
p.r,
p.modelMagErr_r,
p.petroMag_r - p.extinction_r,
p.petroMagErr_r,
p.i,
p.modelMagErr_i,
p.z,
f.psfWidth_r,
r.stripe,
r.strip
FROM
photoObj p
JOIN field f ON f.fieldid = p.fieldid
JOIN run r ON r.run=f.run
WHERE
f.psfWidth_r > 1.2
and p.colc > 400.0
</textarea><textarea style="display:none" id="q_1435232814">-- Find all objects within 30 arcseconds of one another
-- that have very similar colors: that is where the color ratios
-- u-g, g-r, r-I are less than 0.05m. This query introduces the
-- Neighbors table, which is a pre-computed list of the nearest
-- neighbors of each object within 30 arcseconds.
SELECT TOP 10 P.ObjID as objid1, L.ObjID as objid2, N.distance
FROM PhotoPrimary P -- P is the primary object
JOIN Neighbors N ON P.ObjID = N.ObjID -- N is the neighbor link
JOIN PhotoPrimary L ON L.ObjID = N.NeighborObjID -- L is the lens candidate of P
WHERE
P.ObjID < L. ObjID -- avoid duplicates
and abs((P.u-P.g)-(L.u-L.g))<0.05 -- L and P have similar spectra
and abs((P.g-P.r)-(L.g-L.r))<0.05
and abs((P.r-P.i)-(L.r-L.i))<0.05
and abs((P.i-P.z)-(L.i-L.z))<0.05
</textarea><textarea style="display:none" id="q_2060639971">-- Find stars with multiple measurements with magnitude variations >0.1.
-- Note that this runs very slowly unless explicit workarounds are included
-- for some SQLServer Optimizer bugs, which are NOT included here
SELECT TOP 100
S1.objID as objID1, S2.objID as ObjID2 -- select object IDs of star and its pair
FROM Star as S1, -- the primary star
photoObj as S2, -- the second observation of the star
neighbors as N -- the neighbor record
WHERE S1.objID = N.objID -- insist the stars are neighbors
and S2.objID = N.neighborObjID -- using precomputed neighbors table
and distance < 0.5/60 -- distance is 0.5 arc second or less
and S1.run != S2.run -- observations are two different runs
and S2.type = dbo.fPhotoType('Star') -- S2 is indeed a star
and S1.u between 1 and 27 -- S1 magnitudes are reasonable
and S1.g between 1 and 27
and S1.r between 1 and 27
and S1.i between 1 and 27
and S1.z between 1 and 27
and S2.u between 1 and 27 -- S2 magnitudes are reasonable.
and S2.g between 1 and 27
and S2.r between 1 and 27
and S2.i between 1 and 27
and S2.z between 1 and 27
and ( -- and one of the colors is different.
abs(S1.u-S2.u) > .1 + (abs(S1.Err_u) + abs(S2.Err_u))
or abs(S1.g-S2.g) > .1 + (abs(S1.Err_g) + abs(S2.Err_g))
or abs(S1.r-S2.r) > .1 + (abs(S1.Err_r) + abs(S2.Err_r))
or abs(S1.i-S2.i) > .1 + (abs(S1.Err_i) + abs(S2.Err_i))
or abs(S1.z-S2.z) > .1 + (abs(S1.Err_z) + abs(S2.Err_z))
)
</textarea><textarea style="display:none" id="q_1200416665">-- Checking for errors using flags.
-- Another useful query is to see if the errors on moving (or
-- apparently moving) objects are correct. For example, it used to be that
-- some known QSOs were being flagged as moving objects. One way to look for
-- such objects is to compare the velocity to the error in velocity and see if
-- the "OBJECT1_MOVED" or "OBJECT2_BAD_MOVING_FIT" is set.
-- This query introduces bitwise logic for flags, and uses the 'as' syntax to
-- make the query more readable. Note that if a flag is not set, the value
-- will be zero. If you want to ensure multiple flags are not set, you can
-- either check that each individually is zero, or that their sum is zero.
-- (From Gordon Richards)
--
-- NOTE: A caveat about using functons (like fPhotoFlags) is that if your
-- query is selecting a very large number of rows (e.g. hundreds of
-- thousands or millions) then it's that many function calls, and
-- this will slow down the query execution significantly. In that
-- case, you should replace the function call with its equivalent
-- binary bitmask, e.g. if you run the query (with Quick button)
-- SELECT (dbo.fPhotoFlags('MOVED') + dbo.fPhotoFlags('BAD_MOVING_FIT'))
-- you will get the value 36507222016, which you can substitute in
-- first line of the WHERE clause below as:
-- (flags & 36507222016) > 0
-- to avoid zillions of function calls.
SELECT TOP 1000
run,
rerun,
camcol,
field,
objID,
ra, dec,
rowv, colv,
rowvErr, colvErr,
i,
(flags & dbo.fPhotoFlags('MOVED')) as MOVED,
(flags & dbo.fPhotoFlags('BAD_MOVING_FIT')) as BAD_MOVING_FIT
FROM Galaxy
WHERE
(flags & (dbo.fPhotoFlags('MOVED') + dbo.fPhotoFlags('BAD_MOVING_FIT'))) > 0
and (rowv * rowv + colv * colv) >=
(rowvErr * rowvErr + colvErr * colvErr)
</textarea><textarea style="display:none" id="q_1563979474">-- Elliptical galaxies based on model fits.
-- Find all galaxies with a deVaucouleours profile and the
-- photometric colors consistent with an elliptical galaxy.
-- This query has many conditions, and also shows more of the
-- bitwise logic necessary for dealing with flags.
SELECT TOP 100 ObjID
FROM Galaxy as G
WHERE
G.lnlDev_r > G.lnlExp_r + 0.1
-- the likelihood of the deVaucouleours profile fit is 10% greater than the likelihood of the exponential fit
and G.lnlExp_r > -999
-- and the likelihoods are actually meaningful
and (G.flags & (dbo.fPhotoFlags('BINNED1') + dbo.fPhotoFlags('BINNED2') + dbo.fPhotoFlags('BINNED4'))) > 0
--and it is detected from at least one of the binned images ???
and (G.flags & ( dbo.fPhotoFlags('BLENDED') + dbo.fPhotoFlags('NODEBLEND') + dbo.fPhotoFlags('CHILD'))) != dbo.fPhotoFlags('BLENDED')
--and, if it is blended, it is either a child or not deblended further ??
and (G.flags & (dbo.fPhotoFlags('EDGE') + dbo.fPhotoFlags('SATURATED'))) = 0
-- and it is not near a ccd edge or saturated, where measurements may be bad
and G.petroMag_i > 17.5
-- and it is fainter than 17.5 in i-band
and (G.petroMag_r > 15.5 or G.petror50_r > 2)
and (G.petroMag_r > 0 and G.g > 0 and G.r > 0 and G.i > 0)
and ( (G.petroMag_r - G.extinction_r) < 19.2
and (G.petroMag_r - G.extinction_r <
(13.1 + (7/3)*(G.g - G.r) + 4 *(G.r - G.i) - 4 * 0.18 ) )
and ( (G.r - G.i - (G.g - G.r)/4 - 0.18) < 0.2 )
and ( (G.r - G.i - (G.g - G.r)/4 - 0.18) > -0.2 ) )
or ( (G.petroMag_r - G.extinction_r < 19.5)
and ( (G.r - G.i - (G.g - G.r)/4 - 0.18) >
(0.45 - 4*(G.g - G.r) ) )
and ( (G.g - G.r) > (1.35 + 0.25 *(G.r - G.i) ) ) )
-- and many constraints on colors and mags are met to make it have
-- elliptical-type colors.
</textarea><textarea style="display:none" id="q_673740146">-- Galaxies with bluer centers.
-- by Michael Strauss. For all galaxies
-- with r_Petro < 18, not saturated, not bright, and not edge, give me those
-- with centers appreciably bluer than their outer parts, i.e., define the
-- center color as: u_psf - g_psf and define the outer color as: u_model -
-- g_model; give me all objs which have (u_model - g_model) - (u_psf - g_psf)
-- < -0.4
-- Another flags-based query.
SELECT TOP 1000
colc_u, colc_g, objID
FROM Galaxy
WHERE
( Flags & (dbo.fPhotoFlags('SATURATED') +
dbo.fPhotoFlags('BRIGHT') +
dbo.fPhotoFlags('EDGE')) ) = 0
and petrorad_r < 18
and ((colc_u - colc_g) - (psfMag_u - psfMag_g)) < -0.4</textarea><textarea style="display:none" id="q_1080565066">-- Diameter-limited sample of galaxies
-- from James Annis.
-- Another query that makes extensive use of photo flags to get a sample
-- of galaxies within a size range as specified by their i-band Petrosian
-- radius.
SELECT TOP 100
run,
camCol,
rerun,
field,
objID,
ra,
dec
FROM Galaxy
WHERE ( flags & (dbo.fPhotoFlags('BINNED1')
+ dbo.fPhotoFlags('BINNED2')
+ dbo.fPhotoFlags('BINNED4')) ) > 0
and ( flags & (dbo.fPhotoFlags('BLENDED')
+ dbo.fPhotoFlags('NODEBLEND')
+ dbo.fPhotoFlags('CHILD')) ) != dbo.fPhotoFlags('BLENDED')
and ( ( (flags & dbo.fPhotoFlags('NOPETRO') = 0)
and petrorad_i > 15)
or ( (flags & dbo.fPhotoFlags('NOPETRO') > 0)
and petrorad_i > 7.5)
or ( (flags & dbo.fPhotoFlags('TOO_LARGE') > 0)
and petrorad_i > 2.5)
or
( (flags & dbo.fPhotoFlags('SATURATED') = 0)
and petrorad_i > 17.5) )
</textarea><textarea style="display:none" id="q_1549277712">-- Extremely red galaxies.
-- from James Annis.
-- Similar to the diameter limited sample query but selects galaxies that
-- are red (i-z color greater than a certain threshold).
SELECT TOP 1000
g.run,
g.camCol,
g.rerun,
g.field,
g.objID,
g.ra, g.dec
FROM Field f, Galaxy g
WHERE
g.fieldID = f.fieldID
and ( g.flags & (dbo.fPhotoFlags('BINNED1')
+ dbo.fPhotoFlags('BINNED2')
+ dbo.fPhotoFlags('BINNED4')) ) > 0
and ( g.flags & (dbo.fPhotoFlags('BLENDED')
+ dbo.fPhotoFlags('NODEBLEND')
+ dbo.fPhotoFlags('CHILD')) ) != dbo.fPhotoFlags('BLENDED')
and ( g.flags & (dbo.fPhotoFlags('COSMIC_RAY')
+ dbo.fPhotoFlags('INTERP')) ) = 0
and f.psfWidth_r < 1.5
and (g.i - g.z > 1.0 )
</textarea><textarea style="display:none" id="q_1688445031">-- A version of the LRG sample.
-- by James Annis.
-- Another query with many conditions and flag tests that selects Luminous
-- Red Galaxies (LRGs).
SELECT TOP 100
run,
camCol,
rerun,
field,
objID,
ra,
dec
FROM Galaxy
WHERE ( ( flags & (dbo.fPhotoFlags('BINNED1')
+ dbo.fPhotoFlags('BINNED2')
+ dbo.fPhotoFlags('BINNED4')) ) > 0
and ( flags & (dbo.fPhotoFlags('BLENDED')
+ dbo.fPhotoFlags('NODEBLEND')
+ dbo.fPhotoFlags('CHILD')) ) != dbo.fPhotoFlags('BLENDED')
and ( flags & (dbo.fPhotoFlags('EDGE')
+ dbo.fPhotoFlags('SATURATED')) ) = 0
and petroMag_i > 17.5
and (petroMag_r > 15.5 or petror50_r > 2)
and (petroMag_r > 0 and g > 0 and r > 0 and i > 0)
and ( (petroMag_r-extinction_r) < 19.2
and (petroMag_r - extinction_r <
(13.1 + (7/3) * (dered_g - dered_r) + 4 * (dered_r - dered_i) - 4 * 0.18) )
and ( (dered_r - dered_i - (dered_g - dered_r)/4 - 0.18) < 0.2)
and ( (dered_r - dered_i - (dered_g - dered_r)/4 - 0.18) > -0.2)
--dered_ quantities already include extinction
and ( (petroMag_r - extinction_r +
2.5 * LOG10(2 * 3.1415 * petror50_r * petror50_r)) < 24.2) )
or ( (petroMag_r - extinction_r < 19.5)
and ( (dered_r - dered_i - (dered_g - dered_r)/4 - 0.18) > (0.45 - 4 * (dered_g - dered_r)) )
and ( (dered_g - dered_r) > (1.35 + 0.25 * (dered_r - dered_i)) ) )
and ( (petroMag_r - extinction_r +
2.5 * LOG10(2 * 3.1415 * petror50_r * petror50_r) ) < 23.3 ) )
</textarea><textarea style="display:none" id="q_1276987864">-- Spectra of Red Stars
--
-- SDSS-III handles searches by spectral lines differently than previous
-- releases. In addition, spectral lines for galaxies and stars are
-- identified through different processes. See the "Galaxies with
-- Emission Lines" sample query for an example of using galaxy spectra.
--
-- Spectral lines for stars are calculated using the SEGUE Stellar Parameter
-- Pipeline (SSPP; Lee et al. 2008) and are stored in the sppLines
-- table. For more on how spectral lines of stars are found, see
-- the SSPP page of the sdss3.org website.
-- This query selects red stars (spectral type K), with large
-- CaII triplet eq widths, with low errors on the CaII triplet
-- equivalent widths.
SELECT
sl.plate,sl.mjd,sl.fiber,
sl.caIIKside,sl.caIIKerr,sl.caIIKmask,
sp.fehadop,sp.fehadopunc,sp.fehadopn,
sp.loggadopn,sp.loggadopunc
FROM sppLines AS sl
JOIN sppParams AS sp ON sl.specobjid = sp.specobjid
WHERE
fehadop < -3.5
AND fehadopunc between 0.01
and 0.5 and fehadopn > 3
</textarea><textarea style="display:none" id="q_1804992033">-- Galaxy counts on HTM grid.
--
-- Create a count of galaxies for each of the Hierarchical Triangular Mesh (HTM) triangles.
-- Galaxies should satisfy a certain color cut like 0.7u-0.5g-0.2i<1.25 && r<21.75, output
-- it in a form adequate for visualization.
SELECT (htmID / power(2,24)) as htm_8 ,
-- group by 8-deep HTMID (rshift HTM by 12)
avg(ra) as ra,
avg(dec) as [dec],
count(*) as pop -- return center point and count for display
FROM Galaxy -- only look at galaxies
WHERE
-- RA/dec cut added to make query run in Quick mode
(ra between 180 and 181 and dec between -1 and 1) and
(0.7*u - 0.5*g - 0.2*i) < 1.25 -- meeting this color cut
and r < 21.75 -- brighter than 21.75 magnitude in red band.
group by (htmID /power(2,24)) -- group into 8-deep HTM buckets.
</textarea><textarea style="display:none" id="q_1055302504">-- Binary Stars Colors.
--
-- Find binary stars with specific colors.
-- At least one of them should have the colors (meets Paul Szkody's color cut) of a white dwarf.
SELECT TOP 100 s1.objID as s1, s2.objID as s2
FROM Star S1 -- S1 is the white dwarf
JOIN Neighbors N ON S1.objID = N. objID -- N is the precomputed neighbors link
JOIN Star S2 ON S2.objID = N.NeighborObjID -- S2 is the second star
WHERE
N.neighborType = dbo.fPhotoType('Star') -- and S2 is a star
and N.distance < .05 -- the 3 arcsecond test
and ((S1.u - S1.g) < 0.4 ) -- and S1 meets the color cut for
and (S1.g - S1.r) < 0.7 -- white dwarfs.
and (S1.r - S1.i) > 0.4
and (S1.i - S1.z) > 0.4
</textarea><textarea style="display:none" id="q_183659941">-- Galaxies unsaturated near (given) coordinates.
--
-- Find galaxies without saturated pixels within 1' of a given point.
-- ra=185.0, dec=-0.5. This query uses a function fGetNearbyObjEq,
-- which takes 3 arguments (ra,dec, distance in arcmin); this function uses
-- the Neighbors table. The Neighbors table and the Galaxy table have in
-- common the objID, so we have to select objects from both where the objIDs
-- are the same. The output of the function is a table with the Galaxy Object
-- ID and distance in arcmin from the input. This query introduces the use of
-- a JOIN to combine table contents. Also, we use the 'ORDER BY' syntax,
-- which will sort the output.
SELECT TOP 100 G.objID, GN.distance
FROM Galaxy AS G
JOIN dbo.fGetNearbyObjEq(185.,-0.5, 1) AS GN -- this function outputs a table, so we have to do a join
ON G.objID = GN.objID -- get objects from temporary neighbors table GN with desired ObjID
WHERE
(G.flags & dbo.fPhotoFlags('saturated')) = 0 -- and the object is not saturated. f.PhotoFlags is a function that interprets the flag bits.
ORDER BY distance -- sort these by distance
</textarea><textarea style="display:none" id="q_2000917639">-- Search near BCG galaxies.
--
-- For each galaxy in the BCG data set (brightest cluster galaxy),
-- in 160<right ascension<170, -25<declination<35 count the number of
-- galaxies within 30" of it that have a photoz within 0.05
-- of that galaxy.
-- This query has a very complex WHERE clause.
SELECT TOP 1000 G.objID, COUNT(N.NeighborObjID) AS pop
FROM Galaxy AS G -- first gravitational lens candidate
JOIN Neighbors AS N ON G.objID = N.objID -- precomputed list of neighbors
JOIN Galaxy AS U ON U.objID = N.neighborObjID -- a neighbor galaxy of G
JOIN photoZ AS Gpz ON G.objID = Gpz.objID -- photoZ of G.
JOIN photoZ AS Npz ON U.objID = Npz.objID -- neighbor photoZ
WHERE
G.ra BETWEEN 160 AND 170
AND G.dec BETWEEN -5 AND 5
AND N.objID < N.neighborObjID -- 30 arcseconds of one another.
AND ABS(Gpz.Z - Npz.Z) < 0.05 -- restrict the photoZ differences
AND (G.flags & (dbo.fPhotoFlags('BINNED1') + dbo.fPhotoFlags('BINNED2') + dbo.fPhotoFlags('BINNED4'))) > 0
--and it is detected from at least one of the binned images
AND (G.flags & ( dbo.fPhotoFlags('BLENDED') + dbo.fPhotoFlags('NODEBLEND') + dbo.fPhotoFlags('CHILD'))) != dbo.fPhotoFlags('BLENDED')
--and, if it is blended, it is either a child or not deblended further ??
AND (G.flags & (dbo.fPhotoFlags('EDGE') + dbo.fPhotoFlags('SATURATED'))) = 0
-- and it is not near a ccd edge or saturated, where measurements may be bad
-- and apply color cut for a BCG courtesy of James Annis of Fermilab
AND G.petroMag_i > 17.5
AND (G.petroMag_r > 15.5 or G.petror50_r > 2)
AND (G.petroMag_r < 30 AND G.g < 30 AND G.r < 30 AND G.i < 30)
AND (G.r < 19.2
AND ( 1=1 or -- huh?
(G.r < (13.1 + (7/3)*(G.g - G.r) +
-- deRed_r < 13.1 + 0.7 / 0.3 * deRed_gr
4 *(G.r - G.i - 0.18 ))
-- 1.2 / 0.3 * deRed_ri
AND (( G.r - G.i - (G.g - G.r)/4 - 0.18) BETWEEN -0.2 AND 0.2 )
AND ((G.r +
-- petSB - deRed_r + 2.5 log10(2Pi*petror50^2)
2.5 * LOG( 2 * 3.1415 * G.petror50_r * G.petror50_r )) < 24.2 )
)
or
( (G.r < 19.5 )
AND (( G.r - G.i -(G.g - G.r)/4 -.18) >
-- - deRed_gr/4 - 0.18
-- cperp = deRed_ri
(0.45 - 4*( G.g - G.r)))
-- 0.45 - deRed_gr/0.25
AND ((G.g - G.r) > ( 1.35 + 0.25 *(G.r - G.i)))
AND ((G.r +
-- petSB - deRed_r + 2.5 log10(2Pi*petror50^2)
2.5 * LOG( 2 * 3.1415 * G.petror50_r * G.petror50_r )) < 23.3 )
)) )
GROUP BY G.objID
</textarea><textarea style="display:none" id="q_359595534">-- The detectionIndex table contains all detections of a given physical object,
-- which is uniquely identified by the "thingid". In order to extract photometry,
-- you need a join with the PhotoObjAll table, using the objid.
-- There is also a flag field called isPrimary, which is 1 for the object that
-- is found on a primary polygon/field, all the other detections have 0 in this field.
-- Here is a compound query to find all time series around a certain object with a thingid= 97423000
SELECT
LTRIM(STR(mjd_r,20,2)) AS MJD,
dbo.fSDSS(p.objId) AS ID,
modelMag_g, modelMagErr_g,
modelMag_r, modelMagErr_r,
modelMag_i, modelMagErr_i, p.ra, p.dec
INTO #list
FROM detectionindex d
JOIN PhotoObjAll p ON d.objid=p.objid
JOIN Field f ON p.fieldid=f.fieldid
WHERE d.thingid=97423000
ORDER BY 1
GO
--
-- Now find objects near each of the detections
--
SELECT a.*, b.*
FROM #list a
CROSS APPLY dbo.fGetNearbyObjEq(a.ra, a.dec, 0.1) b
</textarea>
<textarea style="display:none" id="q_752833322">-- This query gets the SQL queries per month for a given database name (pattern).
select yy, mm as mth, count(*)
into mydb.MonthyUsageDR8
from sqllogall
where dbname like '%dr8'
group by yy, mm
order by yy, mm</textarea><textarea style="display:none" id="q_652519058">-- This query gets the rough GB served per month from SQL queries on a given database name (pattern).
-- The query assumes a fiducial average row size of 100 bytes and hence divides the total number of
-- rows per month by 10^7 (i.e. 10^9/100) to get the approximate # of GBs returned to the user.
select yy, mm as mth, cast(sum(rows) as float)/10000000 as GB
into mydb.MonthyGBforDR8
from sqllogall
where yy >=2011 and dbname like '%dr8'
group by yy, mm
order by yy, mm
</textarea><textarea style="display:none" id="q_518325890">-- This query gets the SQL queries per quarter for a given year (2012) for a given SQL product (DR8) in the LogSource table.
select datepart(qq,s.thetime) as Qtr, count(*) as Queries
into mydb.QtrlyUsageDR8
from sqllogall s join logsource l on s.logid=l.logid
where s.yy = 2012 and l.product='DR8'
group by datepart(qq,s.thetime)
order by Qtr
-- To get the same data for multiple years, you can do something like:
select (cast(yy as varchar(4)) + '-Q' + cast(datepart(qq,s.thetime) as varchar(1))) as Qtr,
count(*) as Queries
into mydb.QtrlyUsageDR8
from sqllogall s join logsource l on s.logid=l.logid
where s.yy > 2010 and l.product='DR8'
group by yy, datepart(qq,s.thetime)
order by Qtr
</textarea><textarea style="display:none" id="q_1785185606">-- This query gets the Web hits for a given quarter (2012-Q1) for a given Web product (DR8) in the LogSource table.
select count(*) as Hits
into mydb.Q1HitsDR8
from Weblogall s join logsource l on s.logid=l.logid
where s.yy = 2012 and (s.mm between 1 and 3) and l.product='DR8'
</textarea>
</div>
<!--<div style="width:auto; border:none;" class="qpop" id="samplePreviewPane"></div>-->
<div style="width: auto; padding: 0 0 0 0;" class="qpop" id="samplePreviewPane">
</div>
<div id="tableHelpDiv" class="qpopH">
Submitted queries are required to direct their output into a table in MyDB. You
can do this either by manually specifying 'select into' clause within your query,
or by letting CasJobs automatically add the table in this field. Default table names
in this field are usually unique.;
</div>
<div id="contextHelpDiv" class="qpopH">
A <i>context</i> is a unique catalog of data. Use this field to determine where your queries should run.
</div>
<div id="taskNameHelpDiv" class="qpopH">
You can search your job history by taskname, so using a unique value in this field
can help when searching for a particular job.
</div>
<script language="JavaScript" type="text/javascript" src="scripts/cookieMonster.js"></script>
<script type="text/javascript" src="scripts/qspop.js"></script>
<script type="text/javascript" src="scripts/urlcoder.js"></script>
<script type="text/javascript" src="scripts/ajcrp.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment