Re: Query from two tables return error

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: arnaud gaboury <arnaud(dot)gaboury(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Query from two tables return error
Date: 2016-04-01 14:04:13
Message-ID: 56FE7FDD.3070804@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 04/01/2016 06:52 AM, arnaud gaboury wrote:
>
>
> On Fri, Apr 1, 2016 at 3:33 PM, Sándor Daku <daku(dot)sandor(at)gmail(dot)com

>
> One of many difficulties with computers that they do what you say
> them to do, not what you think or you think you are saying. :)
> Lets see:
> SELECT d.home_dir
> FROM email.mail_dir d, email.mailusers u <- make a join between
> mail_dir and mailusers = join every(!) record from the first table
> with every(!) record from the second table
> WHERE u.username='arnaud.gaboury'; <- but I need only those from the
> joined records where the username is arnaud.gaboury
>
> And there, you have it.
>
> You can simply redefine the view.
>
> SELECT *,((mailusers.domain_name || '/'::text) ||
> mailusers.username) || '/'::text AS home_dir
> FROM email.mailusers;
>
>
> Thank you so much. This way I get all needed info in one view.

This might help understand what is going on:

http://www.postgresql.org/docs/9.5/interactive/tutorial-join.html

>
>
> Notice the * after the SELECT statement.
> So you have all the data plus the homedir.
>
> You can leave out the whole view thing and incorporate the home_dir
> expression right into your select.
> Or you can write a function which makes this to you with the usename
> as argument.
>
> Regards,
> Sándor
>
>
>
>
>
> --
>
> google.com/+arnaudgabourygabx
> <https://plus.google.com/_/notifications/emlink?emr=05814804238976922326&emid=CKiv-v6PvboCFcfoQgod6msAAA&path=%2F116159236040461325607%2Fop%2Fu&dt=1383086841306&ub=50>
>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message arnaud gaboury 2016-04-01 14:16:57 Re: Query from two tables return error
Previous Message arnaud gaboury 2016-04-01 13:52:20 Re: Query from two tables return error