<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[FrontAccounting forum — Better sql construct in sales/includes/db/sales_order_db.inc]]></title>
		<link>https://frontaccounting.com/punbb/viewtopic.php?id=10393</link>
		<atom:link href="https://frontaccounting.com/punbb/extern.php?action=feed&amp;tid=10393&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Better sql construct in sales/includes/db/sales_order_db.inc.]]></description>
		<lastBuildDate>Sat, 18 Nov 2023 20:59:20 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Better sql construct in sales/includes/db/sales_order_db.inc]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=42713#p42713</link>
			<description><![CDATA[<p>It doesn&#039;t appear to have been pushed into the GitHub repo yet <strong><a href="https://github.com/FrontAccountingERP/FA/blob/master/sales/includes/db/sales_order_db.inc">here.</a></strong> but is available in the <a href="https://sourceforge.net/p/frontaccounting/git/ci/6c40a3be4a79826087d7abbdd11b483f19decc2a/tree/sales/includes/db/sales_order_db.inc?diff=0b44975d1b3c8f3e3fb28d24d8b45b1a6f71d12c">SF.net repo</a>. Hope the GitHub repo gets synched correctly in time.</p>]]></description>
			<author><![CDATA[null@example.com (apmuthu)]]></author>
			<pubDate>Sat, 18 Nov 2023 20:59:20 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=42713#p42713</guid>
		</item>
		<item>
			<title><![CDATA[Re: Better sql construct in sales/includes/db/sales_order_db.inc]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=42694#p42694</link>
			<description><![CDATA[<p>This has been pushed to stable repo. Thanks.</p><p>Joe</p>]]></description>
			<author><![CDATA[null@example.com (joe)]]></author>
			<pubDate>Wed, 15 Nov 2023 09:10:34 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=42694#p42694</guid>
		</item>
		<item>
			<title><![CDATA[Re: Better sql construct in sales/includes/db/sales_order_db.inc]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=42692#p42692</link>
			<description><![CDATA[<p>Thanks</p>]]></description>
			<author><![CDATA[null@example.com (boxygen)]]></author>
			<pubDate>Wed, 15 Nov 2023 04:04:05 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=42692#p42692</guid>
		</item>
		<item>
			<title><![CDATA[Better sql construct in sales/includes/db/sales_order_db.inc]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=42633#p42633</link>
			<description><![CDATA[<p>At the end of the file <strong>sales/includes/db/sales_order_db.inc</strong> we have:<br /></p><div class="codebox"><pre><code>function last_sales_order_detail($order, $field)
{
        $sql = &quot;SELECT $field
            FROM &quot;.TB_PREF.&quot;sales_order_details d
            WHERE order_no =
            (SELECT order_no FROM &quot;.TB_PREF.&quot;sales_orders o
            WHERE debtor_no=&quot; . db_escape($order-&gt;customer_id) . &quot;
            ORDER BY order_no DESC LIMIT 1)
            ORDER BY d.id DESC LIMIT 1&quot;;        

        $last_query=db_query($sql, &quot;Could not retrieve last order detail&quot;);
        $row = db_fetch_row($last_query);
        return $row == false ? false : $row[0];
}</code></pre></div><p>Kindly change it to:</p><div class="codebox"><pre><code>function last_sales_order_detail($order, $field)
{
        $sql = &quot;SELECT $field
            FROM &quot;.TB_PREF.&quot;sales_order_details d
            LEFT JOIN &quot; .TB_PREF.&quot;sales_orders o on d.order_no=o.order_no
            WHERE debtor_no=&quot; . db_escape($order-&gt;customer_id) . &quot;
            ORDER BY d.id DESC LIMIT 1&quot;;

        $last_query=db_query($sql, &quot;Could not retrieve last order detail&quot;);
        $row = db_fetch_row($last_query);
        return $row == false ? false : $row[0];
}</code></pre></div><p>It uses a left join instead of a secondary select.</p><p>The <strong>on d.order_no=o.order_no</strong> can become <strong>USING (order_no)</strong> to further optimise it.</p>]]></description>
			<author><![CDATA[null@example.com (apmuthu)]]></author>
			<pubDate>Fri, 27 Oct 2023 18:47:39 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=42633#p42633</guid>
		</item>
	</channel>
</rss>
