<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: Get two fields from a subquery in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/get-two-fields-from-a-subquery/qaa-p/13841077#M4871920</link>
    <description>&lt;P&gt;Take a look in &lt;STRONG&gt;&lt;A href="http://dcx.sap.com/index.html#sqla170/en/html/818201106ce21014b860a02bc19e0819.html"&gt;outer apply&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;DIV&gt;&lt;PRE&gt;&lt;SPAN&gt;&lt;/SPAN&gt;select job.jobID as TheJob, job.SkillLevel As Skill, e1.FirstName, e1.Lastname
from job
outer apply (select top 1 employees.FirstName, Employees.lastname where Employees.SkillLevel = jobs.SkillLevel order by LastWorked) as e1
where job.status = 'Open'
&lt;/PRE&gt;&lt;/DIV&gt;


&lt;P&gt;Other possibility would be a WITH clause. &lt;/P&gt;
&lt;P&gt;HTH&lt;/P&gt;</description>
    <pubDate>Thu, 29 Jun 2017 03:00:56 GMT</pubDate>
    <dc:creator>thomas_duemesnil</dc:creator>
    <dc:date>2017-06-29T03:00:56Z</dc:date>
    <item>
      <title>Get two fields from a subquery</title>
      <link>https://community.sap.com/t5/technology-q-a/get-two-fields-from-a-subquery/qaq-p/13841076</link>
      <description>&lt;P&gt;This could easily be my lack of knowledge about SQL syntax, but the SQL/Anywhere 16 docs, and Google haven't yielded much happiness&lt;/P&gt;
&lt;P&gt;Consider (and please forgive typos, as I'm shooting from the hip):&lt;/P&gt;
&lt;DIV&gt;&lt;PRE&gt;&lt;SPAN&gt;&lt;/SPAN&gt;Create Table JobList (
   JobNumber  int not null autoincrement,
   SkillLevel int not null,
   Status varchar(10)
   )

Create Table Employees (
   id   Int not null autoincrement,
   FirstName   varchar(30),
   LastName    varchar(50),
   LastWorked  datetime,
   SkillLevel  int
   )
&lt;/PRE&gt;&lt;/DIV&gt;


&lt;P&gt;Now, for every job in status 'open', I want the first and last name of the employee who hasn't worked the longest, and has the matching SkillLevel.  So this would work:&lt;/P&gt;
&lt;DIV&gt;&lt;PRE&gt;&lt;SPAN&gt;&lt;/SPAN&gt;select job.jobID as TheJob, job.SkillLevel As Skill,
(select top 1 firstname from Employees where skilllevel = skill order by LastWorked) as FName,
(select top 1 lastname from Employees where skilllevel = skill order by LastWorked) as LName
from job where job.status = 'Open'
&lt;/PRE&gt;&lt;/DIV&gt;


&lt;P&gt;It seems some variation of this should work, but I haven't got it yet:&lt;/P&gt;
&lt;DIV&gt;&lt;PRE&gt;&lt;SPAN&gt;&lt;/SPAN&gt;select job.jobID as TheJob, job.SkillLevel As Skill,
e1.FirstName, e1.Lastname, e1.SkillLevel
from job, 
  (select top 1 employees.FirstName, Employees.lastname, Employees.SkillLevel order by LastWorked) as e1
 where job.status = 'Open'
and e1.SkillLevel = jobs.SkillLevel
&lt;/PRE&gt;&lt;/DIV&gt;


&lt;P&gt;Any guidance appreciated.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2017 09:10:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/get-two-fields-from-a-subquery/qaq-p/13841076</guid>
      <dc:creator>BudDurland</dc:creator>
      <dc:date>2017-06-28T09:10:29Z</dc:date>
    </item>
    <item>
      <title>Re: Get two fields from a subquery</title>
      <link>https://community.sap.com/t5/technology-q-a/get-two-fields-from-a-subquery/qaa-p/13841079#M4871922</link>
      <description>&lt;P&gt;I guess the derived table misses a group by SkillLevel, because you want the according "most relaxed" employee per skill level...&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2017 10:20:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/get-two-fields-from-a-subquery/qaa-p/13841079#M4871922</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2017-06-28T10:20:35Z</dc:date>
    </item>
    <item>
      <title>Re: Get two fields from a subquery</title>
      <link>https://community.sap.com/t5/technology-q-a/get-two-fields-from-a-subquery/qaa-p/13841077#M4871920</link>
      <description>&lt;P&gt;Take a look in &lt;STRONG&gt;&lt;A href="http://dcx.sap.com/index.html#sqla170/en/html/818201106ce21014b860a02bc19e0819.html"&gt;outer apply&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;DIV&gt;&lt;PRE&gt;&lt;SPAN&gt;&lt;/SPAN&gt;select job.jobID as TheJob, job.SkillLevel As Skill, e1.FirstName, e1.Lastname
from job
outer apply (select top 1 employees.FirstName, Employees.lastname where Employees.SkillLevel = jobs.SkillLevel order by LastWorked) as e1
where job.status = 'Open'
&lt;/PRE&gt;&lt;/DIV&gt;


&lt;P&gt;Other possibility would be a WITH clause. &lt;/P&gt;
&lt;P&gt;HTH&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jun 2017 03:00:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/get-two-fields-from-a-subquery/qaa-p/13841077#M4871920</guid>
      <dc:creator>thomas_duemesnil</dc:creator>
      <dc:date>2017-06-29T03:00:56Z</dc:date>
    </item>
    <item>
      <title>Re: Get two fields from a subquery</title>
      <link>https://community.sap.com/t5/technology-q-a/get-two-fields-from-a-subquery/qaa-p/13841078#M4871921</link>
      <description>&lt;P&gt;This should work:&lt;/P&gt;
&lt;P&gt;select&lt;BR /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;job.jobID as TheJob, job.SkillLevel As Skill,&lt;BR /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;e1.FirstName, e1.Lastname, e1.SkillLevel&lt;BR /&gt;
from&lt;BR /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;job, Employees e1&lt;BR /&gt;
where&lt;BR /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;job.status = 'Open' and&lt;BR /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;e1.Id = (select top 1 Id from Employees where SkillLevel = job.Skill order by lastWorked) &lt;/P&gt;</description>
      <pubDate>Thu, 29 Jun 2017 03:14:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/get-two-fields-from-a-subquery/qaa-p/13841078#M4871921</guid>
      <dc:creator>fvestjens</dc:creator>
      <dc:date>2017-06-29T03:14:00Z</dc:date>
    </item>
    <item>
      <title>Re: Get two fields from a subquery</title>
      <link>https://community.sap.com/t5/technology-q-a/get-two-fields-from-a-subquery/qaa-p/13841080#M4871923</link>
      <description>&lt;P&gt;Works like a charm!  Many thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jul 2017 10:40:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/get-two-fields-from-a-subquery/qaa-p/13841080#M4871923</guid>
      <dc:creator>BudDurland</dc:creator>
      <dc:date>2017-07-05T10:40:19Z</dc:date>
    </item>
  </channel>
</rss>

