| From: | Jason Aleski <jason(dot)aleski(at)gmail(dot)com> |
|---|---|
| To: | pgsql-sql(at)postgresql(dot)org |
| Subject: | Re: Query Advice |
| Date: | 2017-03-30 18:27:27 |
| Message-ID: | 9b898bec-bc88-f67e-e327-4c04fd169100@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-sql |
I agree, depends what the application is expecting, but if you only
wanted to return each field, would a regular JOIN work? This should
return each field in a separate column.
SELECT t1.name, t2.description, t2.addr, t2.city, t2.stprov, t2.zip
FROM company t1
JOIN postal_addresses AS t2 ON t1.company_id=t2.company_id
WHERE t1.company_id=1731;
-JA-
On 3/30/2017 1:03 PM, Gary Chambers wrote:
> All,
>
> Given the following tables:
>
> company
> -------
> company_id
> name
>
> postal_addresses
> ----------------
> postal_address_id
> company_id
> description
> addr
> city
> stprov
> zip
>
>
> I've been handling joins as such:
>
> select c.company_id,
> array(select concat_ws('|', pa.description, pa.addr, pa.city,
> pa.stprov, pa.zip)
> ) addrs
> from companies c inner join postal_addresses pa using (company_id)
> where company_id = 1731;
>
> Is there a better way to get the company information along with all of
> the
> addresses in a single query? This works, but it requires the additional
> step of splitting the addresses by the the delimiter at the application
> layer.
>
> Thanks for any advice you have.
>
> --
> G.
>
>
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Gary Chambers | 2017-03-30 19:19:54 | Re: Query Advice |
| Previous Message | Rob Sargent | 2017-03-30 18:17:20 | Re: Query Advice |