Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > Oracle > select emp_num from emp SAMPLE(20);

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-11-03, 08:29
AJCG1976 AJCG1976 is offline
Registered User
 
Join Date: Oct 2002
Location: London
Posts: 5
select emp_num from emp SAMPLE(20);

All,

I wonder if you can be some help, the above query returns a random 20% of the table emp.. I would like to beef this up to return a random 20000 rows (845000 in the table) from another table (clients) after I have already done a set of filters in the sql statement i.e.

select *
from le_clients a, le_flags b
where lc_client_id = lf_client_id
and LF_DECEASED_FLAG is null
and LF_MPS_FLAG is null
and LF_GONEAWAY is null
and lc_cust_flag is null
and LF_ET_FLAG is null
and LF_BEREAVE is null
and LF_SCR_OUT is null
and LF_CHIEF_EXEC is NULL
and LF_F2FSUPP_FLAG is null
and lf_utility_flag is null
and LF_STATUS = 'F2F'
and lf_catchment = 'IN_AREA'

Any help would be great....

Rgards

Adam
Reply With Quote
  #2 (permalink)  
Old 02-11-03, 08:55
remivisser remivisser is offline
Registered User
 
Join Date: Dec 2002
Location: Netherlands
Posts: 118
Is this of any help?


SELECT *
FROM
(
select *
from le_clients a, le_flags b
where lc_client_id = lf_client_id
and LF_DECEASED_FLAG is null
and LF_MPS_FLAG is null
and LF_GONEAWAY is null
and lc_cust_flag is null
and LF_ET_FLAG is null
and LF_BEREAVE is null
and LF_SCR_OUT is null
and LF_CHIEF_EXEC is NULL
and LF_F2FSUPP_FLAG is null
and lf_utility_flag is null
and LF_STATUS = 'F2F'
and lf_catchment = 'IN_AREA'
)
SAMPLE (20)

Remi
__________________
Remi Visser

Oracle Database Administrator
(OCP certified 8i)

Homepage: http://home.remidian.com/
Reply With Quote
  #3 (permalink)  
Old 02-11-03, 09:05
NoviceNo1 NoviceNo1 is offline
Registered User
 
Join Date: Jan 2003
Location: Woking
Posts: 107
Quote:
Originally posted by remivisser
Is this of any help?


SELECT *
FROM
(
select *
from le_clients a, le_flags b
where lc_client_id = lf_client_id
and LF_DECEASED_FLAG is null
and LF_MPS_FLAG is null
and LF_GONEAWAY is null
and lc_cust_flag is null
and LF_ET_FLAG is null
and LF_BEREAVE is null
and LF_SCR_OUT is null
and LF_CHIEF_EXEC is NULL
and LF_F2FSUPP_FLAG is null
and lf_utility_flag is null
and LF_STATUS = 'F2F'
and lf_catchment = 'IN_AREA'
)
SAMPLE (20)

Remi


Hi Remi,
When i try this SQL that you gave, i am getting
"SQL command not properly ended" error (ORA-933)

This is the query that i am trying

SELECT *
FROM
(
select * from emp
)
SAMPLE (10)

What could be the reason for this ?
Thanks
__________________
nn
Reply With Quote
  #4 (permalink)  
Old 02-11-03, 09:20
remivisser remivisser is offline
Registered User
 
Join Date: Dec 2002
Location: Netherlands
Posts: 118
ooops, you're right (i didn't test the statemanet before I posted it...)

SQL> create table demo as select object_id from all_objects;

Table created.

SQL> select * from (select * from demo) sample (0.01);
select * from (select * from demo) sample (0.01)
*
ERROR at line 1:
ORA-00933: SQL command not properly ended


SQL> select * from (select * from demo sample (0.01));

OBJECT_ID
----------
19193
19428

This is rather funny behaviour.

It looks like the sample clause has to be directly after the table(and not after a subquery...)

Remi
__________________
Remi Visser

Oracle Database Administrator
(OCP certified 8i)

Homepage: http://home.remidian.com/
Reply With Quote
  #5 (permalink)  
Old 02-11-03, 09:24
remivisser remivisser is offline
Registered User
 
Join Date: Dec 2002
Location: Netherlands
Posts: 118
From the manual:

You can specify SAMPLE only in a query that selects from a single table. Joins are not supported. However, you can achieve the same results by using a CREATE TABLE ... AS SELECT query to materialize a sample of an underlying table and then rewrite the original query to refer to the newly created table sample. If you wish, you can write additional queries to materialize samples for other tables.

Hope this helps!

Remi
__________________
Remi Visser

Oracle Database Administrator
(OCP certified 8i)

Homepage: http://home.remidian.com/
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

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