简体   繁体   English

PostgreSQL-合并多个查询的结果行

[英]PostgreSQL - Combining result-rows from multiple queries

I am having trouble adding two columns together which are from the same table.column, with two different values. 我很难将来自同一table.column的两个列加在一起,并具有两个不同的值。

How do I add the following two queries together to give two new columns with each their own value; 如何将以下两个查询加在一起,以给出两个各自具有各自值的新列;

SELECT
    ... more columns ...
    components.description,
FROM
    ...
WHERE
    graphiccards.id = systems.id AND
    components.id = graphiccards.component_id;

SELECT
    components.description
FROM
    ...
WHERE
    components.id = mainboards.component_id AND
    mainboards.id = systems.mainboard_id

I would like these two results to be on the same row in two different columns. 我希望这两个结果在两个不同列的同一行中。

https://gyazo.com/de8100b645d6e0ccad3d1ec664907246 https://gyazo.com/de8100b645d6e0ccad3d1ec664907246

You may wish to look at the UNION operator 您可能希望看一下UNION运算符

select
  components.description
  stuff as second_column
from mytable where conditions

union

select
  components.description
  stuff2 as second_column
from mytable2 where conditions2

You just need to make sure you have the same nr of columns with the same name. 您只需要确保具有相同名称的相同nr列即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM