sanween
sanween

Reputation: 1

oracle, select form a large table repeated

I hava a table with millions of records.Each record keeps a user's browse hehavior to an item.Like

>BrowseRecordTable  
>| ------------------------|   
>userid,itemid,operatetime

when give me an item id(itmeid1), now i want to find out who browse this item also browse. Here is what i do :
①、select all the record from BrowseRecordTable where itemid = itemid1
②、for each record,get the userid(temp_userid),
and then select the record from BrowseRecordTable where userid = temp_userid in half hour.

when BrowseRecordTable is very large. There is some trouble.
if there is thousands of records of an itemid in ①
then i need to select from BrowseRecordTable Thousands times in ②

if there is a better way to accomplish my task ?

Upvotes: 0

Views: 57

Answers (1)

Lajos Veres
Lajos Veres

Reputation: 13725

Maybe a join like this?

select * from BrowseRecordTable where userid in (
  select userid from BrowseRecordTable where itemid=itemid1)

Upvotes: 1

Related Questions