Help writing a piece of SQL - Mailing list pgsql-sql
From | Nigel Bishop |
---|---|
Subject | Help writing a piece of SQL |
Date | |
Msg-id | 72558D9A7573814BB4082A28843E03D402658B02@intyodc01.uk.ioko365.com Whole thread Raw |
Responses |
Re: Help writing a piece of SQL
(Richard Huxton <dev@archonet.com>)
Re: Help writing a piece of SQL (Niklas Johansson <spot@tele2.se>) |
List | pgsql-sql |
<div class="Section1"><p class="MsoNormal"><font face="Courier New" size="2"><span lang="EN-GB" style="font-size:10.0pt;font-family:"CourierNew"">Hi, I would appreciate some help writing a piece of SQL</span></font><pclass="MsoNormal"><font face="Courier New" size="2"><span lang="EN-GB" style="font-size:10.0pt;font-family:"CourierNew""> </span></font><p class="MsoNormal"><font face="Courier New" size="2"><spanlang="EN-GB" style="font-size:10.0pt;font-family:"Courier New"">PG803</span></font><p class="MsoNormal"><fontface="Courier New" size="2"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> </span></font><pclass="MsoNormal"><font face="Courier New" size="2"><span lang="EN-GB" style="font-size:10.0pt;font-family:"CourierNew"">My table/data looks like this:</span></font><p class="MsoNormal"><fontface="Courier New" size="2"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> </span></font><pclass="MsoNormal"><font face="Courier New" size="2"><span lang="EN-GB" style="font-size:10.0pt;font-family:"CourierNew""> username | domain | sendto </span></font><p class="MsoNormal"><font face="Courier New" size="2"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New"">+-------------+-------------------------------+------------------------------</span></font><p class="MsoNormal"><fontface="Courier New" size="2"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> Postmaster | intthit08.uk.rabbit.com | root</span></font><p class="MsoNormal"><font face="Courier New" size="2"><spanlang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> root | intthit08.uk.rabbit.com | is-unix@rabbit.com</span></font><p class="MsoNormal"><font face="Courier New" size="2"><span lang="EN-GB"style="font-size:10.0pt;font-family:"Courier New""> stoat.griffin | trusting.co.uk | stoat.griffin@rabbit.com</span></font><pclass="MsoNormal"><font face="Courier New" size="2"><span lang="EN-GB" style="font-size:10.0pt;font-family:"CourierNew""> stoat.griffin | trusting.com | stoat.griffin@rabbit.com</span></font><pclass="MsoNormal"><font face="Courier New" size="2"><span lang="EN-GB" style="font-size:10.0pt;font-family:"CourierNew""> stoat.griffin | rusty.co.uk | stoat.griffin@rabbit.com</span></font><pclass="MsoNormal"><font face="Courier New" size="2"><span lang="EN-GB" style="font-size:10.0pt;font-family:"CourierNew""> stoat.griffin | rusty.com | stoat.griffin@rabbit.com</span></font><pclass="MsoNormal"><font face="Courier New" size="2"><span lang="EN-GB" style="font-size:10.0pt;font-family:"CourierNew""> matilda.clematis | trusting.com | matilda.clematis@rabbit.com</span></font><pclass="MsoNormal"><font face="Courier New" size="2"><span lang="EN-GB" style="font-size:10.0pt;font-family:"CourierNew""> matilda.clematis | trusting.co.uk | matilda.clematis@rabbit.com</span></font><pclass="MsoNormal"><font face="Courier New" size="2"><span lang="EN-GB" style="font-size:10.0pt;font-family:"CourierNew""> matilda.clematis | rusty.co.uk | matilda.clematis@rabbit.com</span></font><pclass="MsoNormal"><font face="Courier New" size="2"><span lang="EN-GB" style="font-size:10.0pt;font-family:"CourierNew""> matilda.clematis | rusty.com | matilda.clematis@rabbit.com</span></font><pclass="MsoNormal"><font face="Courier New" size="2"><span lang="EN-GB" style="font-size:10.0pt;font-family:"CourierNew""> * | trusting.com | rusty@rabbit.com</span></font><pclass="MsoNormal"><font face="Courier New" size="2"><span lang="EN-GB" style="font-size:10.0pt;font-family:"CourierNew""> * | trusting.co.uk | rusty@rabbit.com</span></font><pclass="MsoNormal"><font face="Courier New" size="2"><span lang="EN-GB" style="font-size:10.0pt;font-family:"CourierNew""> * | rusty.co.uk | rusty@rabbit.com</span></font><pclass="MsoNormal"><font face="Courier New" size="2"><span lang="EN-GB" style="font-size:10.0pt;font-family:"CourierNew""> * | rusty.com | rusty@rabbit.com</span></font><pclass="MsoNormal"><font face="Courier New" size="2"><span lang="EN-GB" style="font-size:10.0pt;font-family:"CourierNew""> * | windoze.com | windoze@badger.com</span></font><pclass="MsoNormal"><font face="Courier New" size="2"><span lang="EN-GB" style="font-size:10.0pt;font-family:"CourierNew""> * | windoze.co.uk | windoze@badger.com</span></font><pclass="MsoNormal"><font face="Courier New" size="2"><span lang="EN-GB" style="font-size:10.0pt;font-family:"CourierNew""> admin | windoze.co.uk | matilda.clematis@rabbit.com</span></font><pclass="MsoNormal"><font face="Courier New" size="2"><span lang="EN-GB" style="font-size:10.0pt;font-family:"CourierNew""> admin | windoze.com | matilda.clematis@rabbit.com</span></font><pclass="MsoNormal"><font face="Courier New" size="2"><span lang="EN-GB" style="font-size:10.0pt;font-family:"CourierNew""> * | saxon.co.uk | superR@uk.diamond.com</span></font><pclass="MsoNormal"><font face="Courier New" size="2"><span lang="EN-GB" style="font-size:10.0pt;font-family:"CourierNew""> * | saxon.com | superR@uk.diamond.com</span></font><pclass="MsoNormal"><font face="Courier New" size="2"><span lang="EN-GB" style="font-size:10.0pt;font-family:"CourierNew""> </span></font><p class="MsoNormal"><font face="Courier New" size="2"><spanlang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> </span></font><p class="MsoNormal"><font face="CourierNew" size="2"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New"">The query will have theusername and domain passed in as variables.</span></font><p class="MsoNormal"><font face="Courier New" size="2"><spanlang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> </span></font><p class="MsoNormal"><font face="CourierNew" size="2"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New"">If the username and domainexist then return the sendto</span></font><p class="MsoNormal"><font face="Courier New" size="2"><span lang="EN-GB"style="font-size:10.0pt;font-family:"Courier New""> </span></font><p class="MsoNormal"><font face="Courier New"size="2"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New"">The bit I’m struggling with is if theusername doesn’t exist then return the sendto where the domain exists</span></font><p class="MsoNormal"><font face="CourierNew" size="2"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> </span></font><p class="MsoNormal"><fontface="Courier New" size="2"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New"">e.g. username=fred (this doesn’t exist) and domain=rusty.com then return <a href="mailto:rusty@rabbit.com">rusty@rabbit.com</a>,<a href="mailto:matilda.clematis@rabbit.com">matilda.clematis@rabbit.com</a>,<a href="mailto:stoat.griffin@rabbit.com">stoat.griffin@rabbit.com</a></span></font><pclass="MsoNormal"><font face="CourierNew" size="2"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> </span></font><p class="MsoNormal"><fontface="Courier New" size="2"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New"">Anyhelp on this would very much appreciated; it’s been driving me mad for the last day.</span></font><p class="MsoNormal"><fontface="Courier New" size="2"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> </span></font><pclass="MsoNormal"><font face="Courier New" size="2"><span lang="EN-GB" style="font-size:10.0pt;font-family:"CourierNew"">Thanks</span></font><p class="MsoNormal"><font face="Courier New" size="2"><spanlang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> </span></font><p class="MsoNormal"><font face="CourierNew" size="2"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New""> </span></font><p class="MsoNormal"><fontface="Courier New" size="2"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New"">Nigel</span></font><spanlang="EN-GB"></span></div><br /><br />Communications on or through ioko's computer systemsmay be monitored or recorded to secure effective system operation and for other lawful purposes.<br /><br />Unlessotherwise agreed expressly in writing, this communication is to be treated as confidential and the information init may not be used or disclosed except for the purpose for which it has been sent. If you have reason to believe that youare not the intended recipient of this communication, please contact the sender immediately. No employee is authorisedto conclude any binding agreement on behalf of ioko with another party by e-mail without prior express writtenconfirmation.<br /><br />ioko365 Ltd. VAT reg 656 2443 31. Reg no 3048367. All rights reserved.