From: | Andreas Joseph Krogh <andreak(at)officenet(dot)no> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Select clause in JOIN statement |
Date: | 2013-06-14 07:14:43 |
Message-ID: | OrigoEmail.41.ba27c9209458fd4c.13f4185bf48@prod2 |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
<div>På fredag 14. juni 2013 kl. 01:10:51, skrev Luca Vernini <<a href="mailto:lucazeo(at)gmail(dot)com" target="_blank">lucazeo(at)gmail(dot)com</a>>:</div>
<blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div style="display:inline; font-family: monospace; font-size: 12px;">It works.<br>
Also consider views.<br>
<br>
Just used this on a my db:<br>
<br>
SELECT * FROM tblcus_customer<br>
INNER JOIN<br>
( SELECT * FROM tblcus_customer_status WHERE status_id > 0) AS b<br>
ON tblcus_customer.status = b.status_id</div>
</blockquote>
<div> </div>
<div>This query is the same as a normal JOIN:</div>
<div>
<style type="text/css"></style>
<pre class="western" style="background: #ffffff; border: none; padding: 0in">
<font color="#000080"><font face="DejaVu Sans Mono"><b>SELECT</b> </font></font><font color="#000000"><font face="DejaVu Sans Mono">*</font></font>
<font face="DejaVu Sans Mono"><font color="#000080"><b>FROM </b></font><font color="#000000">tblcus_customer</font></font>
<font color="#000000"> </font><font color="#000080"><font face="DejaVu Sans Mono"><b>INNER JOIN</b></font></font>
<font color="#000080"> </font><font color="#000000"><font face="DejaVu Sans Mono">tblcus_customer_status b</font></font>
<font color="#000000"> </font><font color="#000080"><font face="DejaVu Sans Mono"><b>ON </b></font></font><font color="#000000"><font face="DejaVu Sans Mono">tblcus_customer.status = b.status_id </font></font><font color="#000080"><font face="DejaVu Sans Mono"><b>AND </b></font></font><font color="#000000"><font face="DejaVu Sans Mono">b.status_id > </font></font><font color="#0000ff"><font face="DejaVu Sans Mono">0</font></font>
</pre>
or</div>
<div>
<style type="text/css"></style>
<pre class="western" style="background: #ffffff; border: none; padding: 0in">
<font color="#000080"><font face="DejaVu Sans Mono"><b>SELECT</b></font> </font><font color="#000000"><font face="DejaVu Sans Mono">*</font></font>
<font face="DejaVu Sans Mono"><font color="#000080"><b>FROM </b></font><font color="#000000">tblcus_customer</font></font>
<font color="#000000"> </font><font color="#000080"><font face="DejaVu Sans Mono"><b>INNER JOIN</b></font></font>
<font color="#000080"> </font><font color="#000000"><font face="DejaVu Sans Mono">tblcus_customer_status b</font></font>
<font color="#000000"> </font><font color="#000080"><font face="DejaVu Sans Mono"><b>ON </b></font></font><font color="#000000"><font face="DejaVu Sans Mono">tblcus_customer.status = b.status_id</font></font>
<font face="DejaVu Sans Mono"><font color="#000080"><b>WHERE </b></font><font color="#000000">b.status_id > </font><font color="#0000ff">0</font></font></pre>
But you can JOIN on SELECTs selecting arbitrary stuff.</div>
<div> </div>
<div class="origo-email-signature">--<br>
Andreas Joseph Krogh <andreak(at)officenet(dot)no> mob: +47 909 56 963<br>
Senior Software Developer / CTO - OfficeNet AS - http://www.officenet.no<br>
Public key: http://home.officenet.no/~andreak/public_key.asc</div>
<div> </div>
Attachment | Content-Type | Size |
---|---|---|
unknown_filename | text/html | 3.0 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | rawi | 2013-06-18 10:12:04 | apt.postgresql.org vs. Pitti PPA - install error |
Previous Message | Luca Vernini | 2013-06-13 23:10:51 | Re: Select clause in JOIN statement |