Thread: Can I unite 2 selects?

Can I unite 2 selects?

From
"Sterpu Victor"
Date:
Hello
 
Can I write a query where I receive a single result set from many queries?
Something like this: SELECT (SELECT 1 AS t1, 2 AS t2), (SELECT 3 AS t3)
I tried exactly this but the error is: "ERROR:  subquery must return only one column"
But I don't see why it must have only one column.
 
Thank you



This email has been checked for viruses by Avast antivirus software.
www.avast.com



DISCLAIMER:
Acest mesaj de posta electronica si documentele aferente sunt confidentiale. Este interzisa distribuirea, dezvaluirea sau orice alt mod de utilizare a lor. Daca nu sunteti destinatarul acestui mesaj, este interzis sa actionati in baza acestor informatii. Citirea, copierea, distribuirea, dezvaluirea sau utilizarea in alt mod a informatiei continute in acest mesaj constituie o incalcare a legii. Daca ati primit mesajul din greseala, va rugam sa il distrugeti, anuntand expeditorul de eroarea comisa. Intrucat nu poate fi garantat faptul ca posta electronica este un mod sigur si lipsit de erori de transmitere a informatiilor, este responsabilitatea dvs. sa va asigurati ca mesajul (inclusiv documentele alaturate lui) este validat si autorizat spre a fi utilizat in mediul dvs.

Re: Can I unite 2 selects?

From
Adrian Klaver
Date:
On 01/29/2015 10:58 AM, Sterpu Victor wrote:
> Hello
> Can I write a query where I receive a single result set from many queries?
> Something like this: SELECT (SELECT 1 AS t1, 2 AS t2), (SELECT 3 AS t3)
> I tried exactly this but the error is: "ERROR:  subquery must return
> only one column"
> But I don't see why it must have only one column.

postgres@test=# SELECT * from (SELECT 1 AS t1, 2 AS t2) as t, (SELECT 3
AS t3) as s;
  t1 | t2 | t3
----+----+----
   1 |  2 |  3


> Thank you



--
Adrian Klaver
adrian.klaver@aklaver.com


Re: Can I unite 2 selects?

From
Edson Richter
Date:
You mean union?

select 1 as t1
union
select 2 as t2
union
select 3 as t3

?
Atenciosamente,

Edson Carlos Ericksson Richter
On 29-01-2015 16:58, Sterpu Victor wrote:
blockquote.cite { margin-left: 5px; margin-right: 0px; padding-left: 10px; padding-right:0px; border-left: 1px solid #cccccc } blockquote.cite2 {margin-left: 5px; margin-right: 0px; padding-left: 10px; padding-right:0px; border-left: 1px solid #cccccc; margin-top: 3px; padding-top: 0px; } .plain pre, .plain tt { font-family: monospace; font-size: 100%; font-weight: normal; font-style: normal; } a img { border: 0px; }body {font-family: Tahoma;font-size: 12pt;} .plain pre, .plain tt {font-family: Tahoma;font-size: 12pt;}
Hello
 
Can I write a query where I receive a single result set from many queries?
Something like this: SELECT (SELECT 1 AS t1, 2 AS t2), (SELECT 3 AS t3)
I tried exactly this but the error is: "ERROR:  subquery must return only one column"
But I don't see why it must have only one column.
 
Thank you



This email has been checked for viruses by Avast antivirus software.
www.avast.com



DISCLAIMER:
Acest mesaj de posta electronica si documentele aferente sunt confidentiale. Este interzisa distribuirea, dezvaluirea sau orice alt mod de utilizare a lor. Daca nu sunteti destinatarul acestui mesaj, este interzis sa actionati in baza acestor informatii. Citirea, copierea, distribuirea, dezvaluirea sau utilizarea in alt mod a informatiei continute in acest mesaj constituie o incalcare a legii. Daca ati primit mesajul din greseala, va rugam sa il distrugeti, anuntand expeditorul de eroarea comisa. Intrucat nu poate fi garantat faptul ca posta electronica este un mod sigur si lipsit de erori de transmitere a informatiilor, este responsabilitatea dvs. sa va asigurati ca mesajul (inclusiv documentele alaturate lui) este validat si autorizat spre a fi utilizat in mediul dvs.


Re: Can I unite 2 selects?

From
John R Pierce
Date:
On 1/29/2015 10:58 AM, Sterpu Victor wrote:
> Can I write a query where I receive a single result set from many queries?
> Something like this: SELECT (SELECT 1 AS t1, 2 AS t2), (SELECT 3 AS t3)
> I tried exactly this but the error is: "ERROR:  subquery must return
> only one column"
> But I don't see why it must have only one column.

do you want

     1 | 2 | 3

or

     1
     2
     3

as your result?  the first is a join, the 2nd is a union.

--
john r pierce                                      37N 122W
somewhere on the middle of the left coast



Re: Can I unite 2 selects?

From
"Sterpu Victor"
Date:
Thank you.
This is the syntax I was looking for.

------ Original Message ------
From: "Adrian Klaver" <adrian.klaver@aklaver.com>
To: "Sterpu Victor" <victor@caido.ro>; "PostgreSQL General"
<pgsql-general@postgresql.org>
Sent: 1/29/2015 9:09:31 PM
Subject: Re: [GENERAL] Can I unite 2 selects?

On 01/29/2015 10:58 AM, Sterpu Victor wrote:
Hello
Can I write a query where I receive a single result set from many
queries?
Something like this: SELECT (SELECT 1 AS t1, 2 AS t2), (SELECT 3 AS t3)
I tried exactly this but the error is: "ERROR: subquery must return
only one column"
But I don't see why it must have only one column.

postgres@test=# SELECT * from (SELECT 1 AS t1, 2 AS t2) as t, (SELECT 3
AS t3) as s;
t1 | t2 | t3
----+----+----
1 | 2 | 3


Thank you



-- Adrian Klaver
adrian.klaver@aklaver.com


---
This email has been checked for viruses by Avast antivirus software.
http://www.avast.com