SQL QUERY for distinct items [message #332319] |
Tue, 08 July 2008 03:41 |
user71408
Messages: 585 Registered: November 2007 Location: NE
|
Senior Member |
|
|
Hi ,
I wrote a query as follows .
select item from items where item in
(select item from item_skj is,item_sku iku ,datestat dt
where is.cost=iku.cost
and is.dates=dt.datess+1)
and supplier is null;
It displays all the items.But I need to display distinct items.If i add "Distinct " keyword it's taking 20 mins. So please let me know to increase the performance of the query.
Thank you
[Updated on: Tue, 08 July 2008 03:45] Report message to a moderator
|
|
|
|
Re: SQL QUERY for distinct items [message #332322 is a reply to message #332319] |
Tue, 08 July 2008 03:50 |
JRowbottom
Messages: 5933 Registered: June 2006 Location: Sunny North Yorkshire, ho...
|
Senior Member |
|
|
How long does this query take to run:SELECT count(*)
FROM (select item
from items
where item in (select item
from item_skj is
,item_sku iku
,datestat dt
where is.cost=iku.cost
and is.dates=dt.datess+1)
and supplier is null)
I suspect that your query takes nearly 20 minutes to return all the rows, but that you're getting the first rows back in much less time than that.
|
|
|
|
Re: SQL QUERY for distinct items [message #332326 is a reply to message #332320] |
Tue, 08 July 2008 03:53 |
user71408
Messages: 585 Registered: November 2007 Location: NE
|
Senior Member |
|
|
ITEM COST DATESS
___________________________
5678432 2300 jun1808
5678432 4300 jun0908
5678432 3278 jui0808
123456
123456
3211222
3211222
123214
32453
...
Like ths am gettomg 3000 rows.
I want to display distinct records.
|
|
|
|
|
|
|
|
Re: SQL QUERY for distinct items [message #332349 is a reply to message #332343] |
Tue, 08 July 2008 05:03 |
Frank
Messages: 7901 Registered: March 2000
|
Senior Member |
|
|
The query did not do an update, so the number of records retrieved before running the query should match the number of records retrieved after running the query, unless something else changed.
|
|
|
Re: SQL QUERY for distinct items [message #332352 is a reply to message #332338] |
Tue, 08 July 2008 05:05 |
JRowbottom
Messages: 5933 Registered: June 2006 Location: Sunny North Yorkshire, ho...
|
Senior Member |
|
|
There we are - when you run the query without the DISTINCt, you're just measuring how long it takes to return the first set of data - this is not how long it takes to fetch all the data.
The COUNT(*) query wll return nothing until it's fetched all the data back, which seems to be taking about 20 minutes.
Can you post an Explain Plan for the query, and tell us what indexes you've got on the tables, and what columns these indexes are on (USER_IND_COLUMNS is the view for that) and we'll see if we can speed the whole thing up a bit.
|
|
|