Subject Re: [firebird-support] Sloooow query
Author Dimitry Sibiryakov
On 26 Jun 2003 at 10:46, Bisma J wrote:

>The "is_selected" field is marked by the application and if it is
>marked (true) means the student accepted in the "school". I have to
>make sure that my application only marks one row for every student
>selection data, because a student cannot be accepted in more than one

Why do you select students' application then? Why not select a
student itself? An additional field "Accepted_to"?
Then instead "NOT IN (...)" you can simply write "accepted_to is
not null and accepted_to <> this_school".

> (SELECT student_id FROM student_selection
> WHERE is_selected='T'
> AND priority<2
> AND school<>'School A')
>/* sort grade from highest to lowest to make sure */
>/* the school get first highest grade of the students */
>ORDER BY b.grade DESC, b.birth_date;

And I also wonder why your table student_selection is denormalized.
Doesn't you have a table with a list of schools?

>Any idea to make the query run faster?
>For any kind of responses, I thank you in advance.

Bring your schema to third normal form. Think about breaking your
query to pieces in SP.

SY, Dimitry Sibiryakov.