Re: Another SQL query help

  • From: Guillermo Alan Bort <cicciuxdba@xxxxxxxxx>
  • To: joscott2011.mail@xxxxxxxxx
  • Date: Thu, 24 Feb 2011 16:41:01 -0300

maybe something like this:
select distinc(col1),colx from (
select a.col1 col1, a.col2 col2, b.col1 bcol1, b.colx colx
FROM t1 a join t2 b on a.col1 = b.col1)

(haven't really tested it... just thinking out loud) and annoying column
names, btw.
Alan.-


On Thu, Feb 24, 2011 at 3:56 PM, john scott <joscott2011.mail@xxxxxxxxx>wrote:

> I am scrathing my head to write a SQL query to get this information:
>
> I have two tables t1 and t2  with these values
>
> Table t1
> ======
> Col1        Col2
> ------         ------
> 1             One
> 2             Two
> 3             Three
>
> Table t2
> =======
> Col1       Colx
> ------        -------
> 1            Xone
> 2            Xtwo
> 2            Xtwotwo
> 3            XThree
>
> I need to select Col2 from Table t1 and Colx from Table t2 with only
> distinct values for Col1.
>
> Here is what I am expecting
>
> t1.Col2           t2. Colx
> ----------           -----------
> One               Xone
> Two               Xtwo
> Three            XThree
>
> In t2.Colx value Xtwotwo is also acceptable as I need only one distinct
> value from t1.Col2 and don't care for
> whatever shows up under t2.Colx.
>
> Any suggestions?
>
> Thanks,
> John
>

Other related posts: