在POSTGRESQL中查询时如何返回多个结果集

时间:2016-12-28 16:11:48

标签: postgresql

我是postgresql的新手。我想返回2个结果集,在我的查询中,这可能吗?我当前的查询是使用'UNION ALL',我得到的是重复数据。

WITH logged_in AS (
      select exists (select 1 from users where user_name = 'z' and password = 'abc') AS logged_in, user_name, user_type
      from users
      WHERE user_name = 'z'
      AND password = 'abc'
     )

     select logged_in, up.user_type, up.page_name, 'page' AS type
     from logged_in AS l
     JOIN user_application_mappings AS up
     ON l.user_type = up.user_type
     UNION ALL
     select logged_in, fm.user_type, fm.feature_name, 'feature' AS type
     from logged_in AS l
     JOIN user_feature_mapping AS fm
     ON l.user_type = fm.user_type

我只想让我的查询返回以下内容:

**resultset 1:**

ID, user_name, logged_in, user_type
 1    userA       true     admin

**resultset 2:**

   pageName, Description,  type
    feature a    xx          page
    feature b    xx          feature

我怎样才能做到这一点?

感谢

0 个答案:

没有答案