Re: convert query from mysql

From: Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>
To: Mike Andrewjeski <Mike(dot)Andrewjeski(at)businesswire(dot)com>, "pgsql-novice(at)postgresql(dot)org" <pgsql-novice(at)postgresql(dot)org>, Kevin Grittner <kgrittn(at)ymail(dot)com>
Subject: Re: convert query from mysql
Date: 2013-12-17 22:13:13
Message-ID: 52B0CC79.4020807@archidevsys.co.nz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On 18/12/13 11:08, Gavin Flower wrote:
> On 18/12/13 10:55, Mike Andrewjeski wrote:
>> [...]
>> > Here's the mysql query:
>>
>> > select nodes.name, GROUP_CONCAT(node_groups.name) from node_groups,
>> > node_group_memberships, nodes where nodes.id =
>> > node_group_memberships.node_id and node_groups.id =
>> > node_group_memberships.node_group_id and nodes.name IN (SELECT name
>> > from nodes) group by nodes.name order by nodes.name")
> [...]
>
> Just noticed the IN clause...
>
> The semantics of how NULLS are handled is different, but you might
> find it more efficient if you don't use IN, but something like:
>
> (SELECT n2.name FROM nodes n2 WHERE n1.name = n2.name)
>
> I always uses aliases for tables, especially when I'm dealing with
> more than one table in an SQL statement.
>
>
> Cheers,
> Gavin
>
>
Arghhhhhhhh!

Of course within seconds of hitting enter, I realized my brain was not
fully engaged!

EXISTS (SELECT 1 FROM nodes n2 WHERE n1.name = n2.name)

might even work!

Cheers,
Gavin

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message angelina410329 2013-12-18 08:10:23 Re: Recover iPhone Photo with iPhone Photo Recovery
Previous Message Gavin Flower 2013-12-17 22:08:07 Re: convert query from mysql