Re: Obtaining two rows from two different columns in same table

From: MacMax <macmax_at_nospam.it>
Date: Wed, 29 Apr 2015 18:57:36 +0200
Message-ID: <1m3nlwg.1fo4ejbja6280N%macmax_at_nospam.it>


Lew Pitcher <lew.pitcher_at_digitalfreehold.ca> wrote:

> On Wednesday April 29 2015 12:25, in comp.databases.mysql, "Lew Pitcher"
> <lew.pitcher_at_digitalfreehold.ca> wrote:
>
> > On Wednesday April 29 2015 12:21, in comp.databases.mysql, "Lew Pitcher"
> > <lew.pitcher_at_digitalfreehold.ca> wrote:
> >
> >> On Wednesday April 29 2015 11:20, in comp.databases.mysql, "MacMax"
> >> <macmax_at_nospam.it> wrote:
> >>
> >>> Someone can help me?
> >>>
> >>> In one table (rel) i have this structure.
> >>> All three fields are numeric.
> >>>
> >>> id, co1, co2
> >>>
> >>> In another table (users) i have the names...
> >>> id_co, name
> >>> id_co, name
> >>> etc.
> >>>
> >>> I would like this result:
> >>>
> >>> id, name (co1)
> >>> id, name (co2)
> >>
> >> How are the two tables related? For that matter, how are the two tables
> >> defined? Your DDL (SQL that defines the tables - Data Definition
> >> Language) would be of help here.
> >>
> >>> How i can get this?
> >>
> >> Typically, through a table join. But, it depends on how your tables are
> >> defined, specifically with regards to (foreign) keys.
> >
> > I should note that the table join would give you the <<id, name>> part of
> > the resultset.
> >
> > OTOH, a UNION will give you the <<id, co1 / id, co2>> part.
>
> (SELECT id, co1 FROM rel) UNION (SELECT id, co2 FROM rel) ORDER BY id;
>
> >>
> >> Show us your table definitions, and we can help with the query SQL.
> >>
> >
> >

Many thanks for your help,
Tomorrow i will try.
If you come in Italy one beer for you... ;)

Max

-- 
http://www.maxori.it
L'Arte è la capacità di fare cose di nessun valore
e di riuscire a venderle
F. Zappa
Received on Wed Apr 29 2015 - 18:57:36 CEST

Original text of this message