If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > A question on subquery return

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-27-03, 12:12
vwu98034 vwu98034 is offline
Registered User
 
Join Date: Oct 2002
Posts: 37
A question on subquery return

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,

v
Reply With Quote
  #2 (permalink)  
Old 02-27-03, 12:18
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Re: A question on subquery return

How about:

where (not exists (select 1 from pStatus where userid='Robert')
or exists (select 1 from pStatus where userid='Robert' and status='p'))
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #3 (permalink)  
Old 02-27-03, 12:30
vwu98034 vwu98034 is offline
Registered User
 
Join Date: Oct 2002
Posts: 37
Thanks Tony.

That is quick and sharp one.

v.
Reply With Quote
  #4 (permalink)  
Old 02-27-03, 17:38
vwu98034 vwu98034 is offline
Registered User
 
Join Date: Oct 2002
Posts: 37
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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On