<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[FrontAccounting forum — gl_db sql convert where to join]]></title>
		<link>https://frontaccounting.com/punbb/viewtopic.php?id=4795</link>
		<atom:link href="https://frontaccounting.com/punbb/extern.php?action=feed&amp;tid=4795&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in gl_db sql convert where to join.]]></description>
		<lastBuildDate>Fri, 14 Mar 2014 13:04:22 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: gl_db sql convert where to join]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=19523#p19523</link>
			<description><![CDATA[<p>Then <strong>INNER JOIN</strong> would be a good replacement for the last join as it mimics the WHERE very well and uses the indices when available.</p>]]></description>
			<author><![CDATA[null@example.com (apmuthu)]]></author>
			<pubDate>Fri, 14 Mar 2014 13:04:22 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=19523#p19523</guid>
		</item>
		<item>
			<title><![CDATA[Re: gl_db sql convert where to join]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=19516#p19516</link>
			<description><![CDATA[<p>No, this is not good idea. Left join is right when record in the table on the right of join is otpional. This is not the case here.<br />Janusz</p>]]></description>
			<author><![CDATA[null@example.com (itronics)]]></author>
			<pubDate>Fri, 14 Mar 2014 09:39:27 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=19516#p19516</guid>
		</item>
		<item>
			<title><![CDATA[gl_db sql convert where to join]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=19472#p19472</link>
			<description><![CDATA[<div class="codebox"><pre><code>--- gl/includes/db/gl_db_bank_trans.inc    Mon Mar 10 16:17:11 2014
+++ gl/includes/db/gl_db_bank_trans.inc    Sat Jan 04 02:23:22 2014
@@ -66,17 +66,17 @@
 function get_bank_trans($type, $trans_no=null, $person_type_id=null, $person_id=null)
 {
     $sql = &quot;SELECT bt.*, act.*,
-        IFNULL(abs(dt.ov_amount), IFNULL(ABS(st.ov_amount), bt.amount)) settled_amount,
-        IFNULL(abs(dt.ov_amount/bt.amount), IFNULL(ABS(st.ov_amount/bt.amount), 1)) settle_rate,
-        IFNULL(debtor.curr_code, IFNULL(supplier.curr_code, act.bank_curr_code)) settle_curr
+        IFNULL(ABS(dt.ov_amount), IFNULL(ABS(st.ov_amount), bt.amount)) AS settled_amount,
+        IFNULL(ABS(dt.ov_amount/bt.amount), IFNULL(ABS(st.ov_amount/bt.amount), 1)) AS settle_rate,
+        IFNULL(debtor.curr_code, IFNULL(supplier.curr_code, act.bank_curr_code)) AS settle_curr
 
         FROM &quot;.TB_PREF.&quot;bank_trans bt
-                 LEFT JOIN &quot;.TB_PREF.&quot;debtor_trans dt ON dt.type=bt.type AND dt.trans_no=bt.trans_no
-                 LEFT JOIN &quot;.TB_PREF.&quot;debtors_master debtor ON debtor.debtor_no = dt.debtor_no
-                 LEFT JOIN &quot;.TB_PREF.&quot;supp_trans st ON st.type=bt.type AND st.trans_no=bt.trans_no
-                 LEFT JOIN &quot;.TB_PREF.&quot;suppliers supplier ON supplier.supplier_id = st.supplier_id,
-             &quot;.TB_PREF.&quot;bank_accounts act
-        WHERE act.id=bt.bank_act &quot;;
+                LEFT JOIN &quot;.TB_PREF.&quot;debtor_trans dt ON dt.type=bt.type AND dt.trans_no=bt.trans_no
+                LEFT JOIN &quot;.TB_PREF.&quot;debtors_master debtor ON debtor.debtor_no = dt.debtor_no
+                LEFT JOIN &quot;.TB_PREF.&quot;supp_trans st ON st.type=bt.type AND st.trans_no=bt.trans_no
+                LEFT JOIN &quot;.TB_PREF.&quot;suppliers supplier ON supplier.supplier_id = st.supplier_id
+                LEFT JOIN &quot;.TB_PREF.&quot;bank_accounts act ON act.id = bt.bank_act
+        WHERE  1 &quot;;
     if ($type != null)
         $sql .= &quot; AND bt.type=&quot;.db_escape($type);
     if ($trans_no != null)
@@ -85,7 +85,7 @@
         $sql .= &quot; AND bt.person_type_id = &quot;.db_escape($person_type_id);
     if ($person_id != null)
         $sql .= &quot; AND bt.person_id = &quot;.db_escape($person_id);
-    $sql .= &quot; ORDER BY trans_date, bt.id&quot;;
+    $sql .= &quot; ORDER BY bt.trans_date, bt.id&quot;;
 
     return db_query($sql, &quot;query for bank transaction&quot;);
 }</code></pre></div><p>Converting the WHERE static clause to a LEFT JOIN would be elegant. Joe, can you add this please.</p>]]></description>
			<author><![CDATA[null@example.com (apmuthu)]]></author>
			<pubDate>Wed, 12 Mar 2014 15:14:55 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=19472#p19472</guid>
		</item>
	</channel>
</rss>
