Here is subquery for a table, called pStatus
pStatus
userid
status
select 1 from pStatus where userid='Robert' and status='p'
How to modify this query so that it also return true if there is't an entry for userid 'Robert'?
Thanks,
vHow about:
where (not exists (select 1 from pStatus where userid='Robert')
or exists (select 1 from pStatus where userid='Robert' and status='p'))|||Thanks Tony.
That is quick and sharp one.
v.|||When I posted this question, I was thinking about using only one "select". The subquery is a small section of a long query with near 1,700 characters. And there are 10 similar subqueries in the query statement needed to have the same change. After running the planner, the performane doesn't seem too bad.
Nested Loop (cost=1.16..33.58 rows=1 width=398) (actual time=2.00..2.00 rows=0 loops=1)
...
Total runtime: 7.00 msec
Only few data at this moment.
v.
No comments:
Post a Comment