query help

query help

am 20.08.2010 23:30:03 von Steven Buehler

------=_NextPart_000_001B_01CB4084.F1218E40
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit

I am hoping that I can do this with one query, I have a table, "Domains"
with 3 columns
accountID, domainID, mailname



what I am trying to do is find all accountID's for "domainID" of 12345 and
see if a second row with "domainID" of 54321 exists for that
"accountID,mailname". If it doesn't exist, I want it to insert another row
with the same accountID and mailname, but with the second (54321) domainid.



Any help would be appreciated.



Thanks

Steve


------=_NextPart_000_001B_01CB4084.F1218E40--

Re: query help

am 21.08.2010 18:13:01 von Travis Ard

Something like this might work:

insert into domains
select a.accountid, reverse(a.domainid), a.mailname
from domains a
left outer join domains b on b.domainid = reverse(a.domainid) and
b.accountid = a.accountid and b.mailname = a.mailname
where b.domainid is null;

-Travis

--------------------------------------------------
From: "Steven Buehler"
Sent: Friday, August 20, 2010 3:30 PM
To:
Subject: query help

> I am hoping that I can do this with one query, I have a table, "Domains"
> with 3 columns
> accountID, domainID, mailname
>
>
>
> what I am trying to do is find all accountID's for "domainID" of 12345 and
> see if a second row with "domainID" of 54321 exists for that
> "accountID,mailname". If it doesn't exist, I want it to insert another
> row
> with the same accountID and mailname, but with the second (54321)
> domainid.
>
>
>
> Any help would be appreciated.
>
>
>
> Thanks
>
> Steve
>
>

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql-2@m.gmane.org