I have the following SQL query:
SELECT EXISTS (SELECT r.id FROM Rules r INNER JOIN rule_t c on c.id=r.rule_t.id
INNER JOIN user u on u.id = r.user_id
WHERE u.fmnum='2813'
AND c.name='default') ::int
Is there a way I can modify this so that I get two values back, the INT from the EXISTS method, and r.id?
I know that I can change the query so that I remove the EXISTS method... if the sub select returns anything at all, then I know the record exists... but I'm just wondering if its possible to do the above.
Thanks.
EDIT 1
I'm testing the following code in a new query window in pgadmin3...
SELECT *
FROM (
SELECT TRUE, r.id
FROM rules r
JOIN rule_t c on c.id = r.rule_t.id
JOIN user u on u.id = r.user_id
WHERE u.fmnum = '2813'
AND c.name = 'default'
);
But I'm getting the following error:
ERROR: subquery in FROM must have an alias LINE 2: ( ^ HINT: For example, FROM (SELECT ...) [AS] foo.
EDIT 2
SELECT *
FROM (
SELECT TRUE, r.id
FROM rules r
JOIN rule_t c on c.id = r.rule_t.id
JOIN user u on u.id = r.user_id
WHERE u.fmnum = '2813'
AND c.name = 'default'
) AS x;