Resolve performance overhead for Oracle order by query [closed] - sql

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have a query that fetches over a million of records. With regular select, I dont see any issue and its taking under 1 sec to returns the records.
My requirement is to get top 10 rows after applying order by clause. Its taking around 1 minute to do even after having necessary indexes on tables involved.
Could someone recommend a solution to get top 10 rows after applying sorting?

Have you tried :
Select * from (
/*Your query goes here
With order by part*/)
where rownum <=10;

Related

How to you use Max and Min expression in Ms Access SQL? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
CrimeData Table for 12 months
Crime Took place in Easternmost
I need to find the following:
Q.7 What type of Crime takes place in the …
(a) Easternmost ………………..
(b) Westernmost ………………..
(c) Northernmost………………..
(d) Southernmost………………..
I tried to find the crime took place in the Easternmost using the following SQL code
SELECT Max(CrimeData.Easting) AS MaxOfEasting, CrimeData.Type
FROM CrimeData
GROUP BY CrimeData.Type;
but I got more than one crime and also other Easting numbers. Can you please tell me if there are other good ways to find the solution.
Please see the attached pictures :)
Rather than using Max/Min, have a look at the TOP keyword in SQL. Some SQL might look like:
SELECT TOP 1 CD.*
FROM CrimeData CD
ORDER BY CD.Easting DESC;
Regards,

SQL group by - can it be this simple? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
can someone please check if this is correct?
Not sure if my answer to Q6 is correct, I am not sure if the group_by I am using is right or not, the rest I think is ok
Thanks
You are close. You need to:
Use COUNT() instead of SUM().
There's no need to use the HAVING clause.
Optionally, you can add aliases to the columns, so they become easier to read.
Your query should look like:
select a.author_id, count(*) as titles, sum(b.quantity_ordered) as units
from a join b on a.book_id = b.book_id
group by a.author_id

regexp_like vs like operator : Oracle [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I am searching for multiple phrases using SQL 'like' operator. Same results can be extracted using Regexp_like function in Oracle. Which one is better/efficient to use and why? My observation is that 'like' works much quicker than regEX.
I am running my queries against very large dataset with few million rows.
Here are both the versions of the query
Using like:
select
name
from
table
where
lower(result) like '%the condition is absent%'
or lower(result) like '%partial presence of disease%'
Using Regexp_like():
select
name
from
table
where
regexp_like(lower(result),'^.*(the condition is absent)|(partial presence of disease).*$')

Display endless amount of data in sql [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
If I have an endless amount of data, can I display all of it in sql?
I know there is obviously select *, but then it will never complete.
Is there a command for this?
You can use TOP to select subset of total records
SELECT TOP 100 * from table
This selects top 100 records.
By using Order By clause , you can specify the basis on which subset of records is returned.
Now if you are asking about limits of Sql Server database management system then please see this link - Maximum Capacity Specification of Sql Server
Eg
Max Databases per instance of SQL Server ( both 32 bit and 64 bit ) = 32,767
Usually, you will prefer to use some kind of paging, since you cannot actually show "endless amount of data" in user-friendly way on application.

Fulltext index query - illogical [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a fulltext index on my table but am getting weird results...
Think a table of current Toys... (huggle buddy is "hot" apparently at the moment)
If a I search for Huggle on my table the results brought up are "Huggle Buddy" toys and I get 12 results...thats fine, perfect.
But if I search for "Huggle Buddy" I get almost 500 results, which is ok as i know its searching both words and combinations, but, the items with Huggle Buddy in the title do not appear first, how do i fix that? e.g. Is there an order by scoring?
Put the search term in quotes so it will only search for an exact match. You'll only get results that contain the exact match "Huggle Buddy".