<?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: Flexible search query using three tables in CRM and CX Q&amp;A</title>
    <link>https://community.sap.com/t5/crm-and-cx-q-a/flexible-search-query-using-three-tables/qaa-p/12017336#M380583</link>
    <description>&lt;P&gt; &lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt; SELECT * FROM
 ({{
      SELECT {c.name}, {c.uid}, {c.pk} FROM {Customer as c}
 }}) c
 JOIN
 ({{ 
     SELECT * FROM
    ({{
        SELECT {o.creationtime}, {o.user}, {o.deliveryaddress} FROM {Order as o}
    }}) o
    INNER JOIN
    ({{
        SELECT MAX({o.creationtime}) as mindate, {o.user} as minuser
          FROM {Order as o}
        GROUP BY {o.user}
    }}) x ON o.createdts=x.mindate
  }}) o
  ON o.p_user = c.pk
  JOIN
  ({{
      SELECT {a.cellphone}, {a.country}, {a.pk} FROM {Address as a}
  }}) a
  ON o.p_deliveryaddress = a.pk
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 05 Apr 2018 12:26:17 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2018-04-05T12:26:17Z</dc:date>
    <item>
      <title>Flexible search query using three tables</title>
      <link>https://community.sap.com/t5/crm-and-cx-q-a/flexible-search-query-using-three-tables/qaq-p/12017326</link>
      <description>&lt;P&gt;I have three tables Order,Customer,Address.&lt;/P&gt;
&lt;P&gt;Can i know how to join three tables in flexible search to get below :&lt;/P&gt;
&lt;P&gt;Customer name;
E-mail address;
Phone Number from address table;
Country;
Date of most recent order.&lt;/P&gt;
&lt;P&gt;Any help would be appreciated?&lt;/P&gt;</description>
      <pubDate>Fri, 30 Mar 2018 08:34:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/crm-and-cx-q-a/flexible-search-query-using-three-tables/qaq-p/12017326</guid>
      <dc:creator>mohammed24</dc:creator>
      <dc:date>2018-03-30T08:34:31Z</dc:date>
    </item>
    <item>
      <title>Re: Flexible search query using three tables</title>
      <link>https://community.sap.com/t5/crm-and-cx-q-a/flexible-search-query-using-three-tables/qaa-p/12017327#M380574</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Below query should return data you need:&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt; SELECT {c.name}, {c.uid}, {a.cellphone}, {a.country}, {o.creationtime} FROM {Customer as c}, {Address as a}, {Order as o} WHERE {c.pk} = {o.user} AND {o.deliveryaddress} = {a.pk} ORDER BY {o.creationtime} DESC LIMIT 1

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Depending on your needs you might want to change &lt;CODE&gt;o.creationtime&lt;/CODE&gt; to  &lt;CODE&gt;o.modifiedtime&lt;/CODE&gt;. You might also have to update fieldnames to match your custom modifications.&lt;/P&gt;
&lt;P&gt;Best regards,&lt;BR /&gt;
&lt;/P&gt;</description>
      <pubDate>Fri, 30 Mar 2018 12:39:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/crm-and-cx-q-a/flexible-search-query-using-three-tables/qaa-p/12017327#M380574</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2018-03-30T12:39:34Z</dc:date>
    </item>
    <item>
      <title>Re: Flexible search query using three tables</title>
      <link>https://community.sap.com/t5/crm-and-cx-q-a/flexible-search-query-using-three-tables/qaa-p/12017328#M380575</link>
      <description>&lt;P&gt;  Thanks Jakub..When i use LIMIT it says incorrect syntax near LIMT?
&lt;/P&gt;</description>
      <pubDate>Fri, 30 Mar 2018 13:09:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/crm-and-cx-q-a/flexible-search-query-using-three-tables/qaa-p/12017328#M380575</guid>
      <dc:creator>mohammed24</dc:creator>
      <dc:date>2018-03-30T13:09:35Z</dc:date>
    </item>
    <item>
      <title>Re: Flexible search query using three tables</title>
      <link>https://community.sap.com/t5/crm-and-cx-q-a/flexible-search-query-using-three-tables/qaa-p/12017329#M380576</link>
      <description>&lt;P&gt;Please check if you didn't misspelled (LIMT). Alternatively you can remove &lt;CODE&gt;LIMIT 1&lt;/CODE&gt; and use &lt;CODE&gt;TOP 1&lt;/CODE&gt;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt; SELECT TOP 1 {c.name}, {c.uid}, {a.cellphone}, {a.country}, {o.creationtime} 
 FROM {Customer as c}, {Address as a}, {Order as o} 
 WHERE {c.pk} = {o.user} AND {o.deliveryaddress} = {a.pk} 
 ORDER BY {o.creationtime} DESC

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Regards,&lt;BR /&gt;
&lt;/P&gt;</description>
      <pubDate>Fri, 30 Mar 2018 13:40:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/crm-and-cx-q-a/flexible-search-query-using-three-tables/qaa-p/12017329#M380576</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2018-03-30T13:40:42Z</dc:date>
    </item>
    <item>
      <title>Re: Flexible search query using three tables</title>
      <link>https://community.sap.com/t5/crm-and-cx-q-a/flexible-search-query-using-three-tables/qaa-p/12017330#M380577</link>
      <description>&lt;P&gt; both LIMIT &amp;amp; (LIMT) as well doesnt work for me...When i use TOP 1 its gives only one record out of 300 records in total.
&lt;/P&gt;</description>
      <pubDate>Fri, 30 Mar 2018 13:48:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/crm-and-cx-q-a/flexible-search-query-using-three-tables/qaa-p/12017330#M380577</guid>
      <dc:creator>mohammed24</dc:creator>
      <dc:date>2018-03-30T13:48:51Z</dc:date>
    </item>
    <item>
      <title>Re: Flexible search query using three tables</title>
      <link>https://community.sap.com/t5/crm-and-cx-q-a/flexible-search-query-using-three-tables/qaa-p/12017331#M380578</link>
      <description>&lt;P&gt;So do you want to get that information for most recent order globally (that's how I understood your question) or most recent order for every customer (or address)?
&lt;/P&gt;</description>
      <pubDate>Fri, 30 Mar 2018 14:01:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/crm-and-cx-q-a/flexible-search-query-using-three-tables/qaa-p/12017331#M380578</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2018-03-30T14:01:52Z</dc:date>
    </item>
    <item>
      <title>Re: Flexible search query using three tables</title>
      <link>https://community.sap.com/t5/crm-and-cx-q-a/flexible-search-query-using-three-tables/qaa-p/12017332#M380579</link>
      <description>&lt;P&gt; i want to fetch  most recent order for every customer based upon the order creation time 
&lt;/P&gt;</description>
      <pubDate>Fri, 30 Mar 2018 14:05:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/crm-and-cx-q-a/flexible-search-query-using-three-tables/qaa-p/12017332#M380579</guid>
      <dc:creator>mohammed24</dc:creator>
      <dc:date>2018-03-30T14:05:43Z</dc:date>
    </item>
    <item>
      <title>Re: Flexible search query using three tables</title>
      <link>https://community.sap.com/t5/crm-and-cx-q-a/flexible-search-query-using-three-tables/qaa-p/12017333#M380580</link>
      <description>&lt;P&gt;Please try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt; SELECT {c.name}, {c.uid}, {a.cellphone}, {a.country}, MIN ({o.creationtime}) 
 FROM {Customer as c}, {Address as a}, {Order as o} 
 WHERE {c.pk} = {o.user} AND {o.deliveryaddress} = {a.pk} 
 GROUP BY {c.name}, {c.uid}, {a.cellphone}, {a.country}

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Regards,&lt;BR /&gt;
&lt;/P&gt;</description>
      <pubDate>Fri, 30 Mar 2018 14:34:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/crm-and-cx-q-a/flexible-search-query-using-three-tables/qaa-p/12017333#M380580</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2018-03-30T14:34:39Z</dc:date>
    </item>
    <item>
      <title>Re: Flexible search query using three tables</title>
      <link>https://community.sap.com/t5/crm-and-cx-q-a/flexible-search-query-using-three-tables/qaa-p/12017334#M380581</link>
      <description>&lt;P&gt; The above one still gives me two ormore than two order's.
&lt;/P&gt;</description>
      <pubDate>Mon, 02 Apr 2018 07:20:04 GMT</pubDate>
      <guid>https://community.sap.com/t5/crm-and-cx-q-a/flexible-search-query-using-three-tables/qaa-p/12017334#M380581</guid>
      <dc:creator>mohammed24</dc:creator>
      <dc:date>2018-04-02T07:20:04Z</dc:date>
    </item>
    <item>
      <title>Re: Flexible search query using three tables</title>
      <link>https://community.sap.com/t5/crm-and-cx-q-a/flexible-search-query-using-three-tables/qaa-p/12017335#M380582</link>
      <description>&lt;P&gt;Using "PagedFlexibleSearchService" is  better way
&lt;/P&gt;</description>
      <pubDate>Mon, 02 Apr 2018 15:22:28 GMT</pubDate>
      <guid>https://community.sap.com/t5/crm-and-cx-q-a/flexible-search-query-using-three-tables/qaa-p/12017335#M380582</guid>
      <dc:creator>sachinsaxena_1</dc:creator>
      <dc:date>2018-04-02T15:22:28Z</dc:date>
    </item>
    <item>
      <title>Re: Flexible search query using three tables</title>
      <link>https://community.sap.com/t5/crm-and-cx-q-a/flexible-search-query-using-three-tables/qaa-p/12017336#M380583</link>
      <description>&lt;P&gt; &lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt; SELECT * FROM
 ({{
      SELECT {c.name}, {c.uid}, {c.pk} FROM {Customer as c}
 }}) c
 JOIN
 ({{ 
     SELECT * FROM
    ({{
        SELECT {o.creationtime}, {o.user}, {o.deliveryaddress} FROM {Order as o}
    }}) o
    INNER JOIN
    ({{
        SELECT MAX({o.creationtime}) as mindate, {o.user} as minuser
          FROM {Order as o}
        GROUP BY {o.user}
    }}) x ON o.createdts=x.mindate
  }}) o
  ON o.p_user = c.pk
  JOIN
  ({{
      SELECT {a.cellphone}, {a.country}, {a.pk} FROM {Address as a}
  }}) a
  ON o.p_deliveryaddress = a.pk
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Apr 2018 12:26:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/crm-and-cx-q-a/flexible-search-query-using-three-tables/qaa-p/12017336#M380583</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2018-04-05T12:26:17Z</dc:date>
    </item>
  </channel>
</rss>

