Home » SQL & PL/SQL » SQL & PL/SQL » returning distinct ID from both queries using OR
returning distinct ID from both queries using OR [message #252865] Fri, 20 July 2007 07:46 Go to next message
rzkhan
Messages: 345
Registered: March 2005
Senior Member
Hi All

query1 returns 248 records
Query2 returns 264 records
Query3 should return maximum of Query1 OR Query2 records
while it returns 274




My aims is to include distinct member_id from both query 1 and query2 to be passed to query3







Please remove my doubt.

Thanks
Riaz



select count(*) as count_query1 from(
select distinct member_id
from attendance
where to_char(a_date,'MON') like 'JUN' and to_char(a_date,'YYYY') like '2007')
/



select count(*)  as count_query2 from
(
select distinct member_id
from extra
where to_char(ext_date,'MON') like 'JUN' and to_char(ext_date,'YYYY') like '2007')
/


select count(*) count_using_or_query1_query2 from(
SELECT ALL NET.MEMBER_ID, NET.BALANCE, NET.M, NET.Y
FROM NET
where m='JUN'
and y=2007
and member_id IN
(
select distinct member_id
from attendance
where to_char(a_date,'MON') like 'JUN' and to_char(a_date,'YYYY') like '2007'
)
OR member_id IN
(
select distinct member_id
from extra
where to_char(ext_date,'MON') like 'JUN' and to_char(ext_date,'YYYY') like '2007')
order by to_number(net.member_id))
/

Re: returning distinct ID from both queries using OR [message #252874 is a reply to message #252865] Fri, 20 July 2007 08:06 Go to previous message
Michel Cadot
Messages: 64103
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Maybe because you have common member_id in both queries.

Regards
Michel
Previous Topic: is windows xp compatible with oracle 9i?
Next Topic: to insert a record thru view
Goto Forum:
  


Current Time: Sat Dec 03 07:55:55 CST 2016

Total time taken to generate the page: 0.14299 seconds