<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[FrontAccounting forum — gl_db sql convert where to join]]></title>
	<link rel="self" href="https://frontaccounting.com/punbb/extern.php?action=feed&amp;tid=4795&amp;type=atom" />
	<updated>2014-03-14T13:04:22Z</updated>
	<generator>PunBB</generator>
	<id>https://frontaccounting.com/punbb/viewtopic.php?id=4795</id>
		<entry>
			<title type="html"><![CDATA[Re: gl_db sql convert where to join]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=19523#p19523" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2014-03-14T13:04:22Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=19523#p19523</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: gl_db sql convert where to join]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=19516#p19516" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[itronics]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=89</uri>
			</author>
			<updated>2014-03-14T09:39:27Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=19516#p19516</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[gl_db sql convert where to join]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=19472#p19472" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2014-03-12T15:14:55Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=19472#p19472</id>
		</entry>
</feed>
